Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: create a Swift version example of the ios-notification-images doc #8185

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion docs/messaging/ios-notification-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ end

![step-2](/assets/docs/messaging/ios-notification-images-step-2.gif)

### Step 3 - Use the extension helper
### Step 3 - Use the extension helper (Objective-C)

> If you selected to create your extension as a Swift project, jump to the next section.

At this point everything should still be running normally. This is the final step which is invoking the extension helper.

Expand All @@ -68,6 +70,34 @@ At this point everything should still be running normally. This is the final ste

![step-3](/assets/docs/messaging/ios-notification-images-step-3.gif)

### Step 3 - Use the extension helper (Swift)

At this point everything should still be running normally. This is the final step which is invoking the extension helper.

- From the navigator select your `ImageNotification` extension
- Open the `NotificationService.swift` file
- At the top of the file import `Firebase` right after the `NotificationService` as shown below

```diff
import UserNotifications
+ import Firebase
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure why the import here is Firebase instead of FirebaseMessaging - by following the steps in the doc, only Firebase is available.


class NotificationService: UNNotificationServiceExtension {
```

- then replace everything from line 19 to 23 with the extension helper

```diff
if let bestAttemptContent = bestAttemptContent {
- // Modify the notification content here...
- bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
-
- contentHandler(bestAttemptContent)
+ Messaging.serviceExtension()
+ .populateNotificationContent(bestAttemptContent, withContentHandler: contentHandler)
}
```

## All done

Run the app and check it builds successfully – **make sure you have the correct target selected**. Now you can use the [Notifications composer](https://console.firebase.google.com/u/0/project/_/notification) to test sending notifications with an image (`300KB` max size). You can also create custom notifications via [`FCM HTTP`](https://firebase.google.com/docs/cloud-messaging/http-server-ref) or [`firebase-admin`](https://www.npmjs.com/package/firebase-admin). Read this page to send [messages from a server](/messaging/server-integration).
Loading