Skip to content

Commit

Permalink
docs: create a Swift version example of the ios-notification-images d…
Browse files Browse the repository at this point in the history
…oc (#8185)

* docs: create a Swift version example of the ios-notification-images doc
* fix: fix syntax highlighting in ios-notification-images
* style(lint): result of `yarn lint:markdown --write`

---------

Co-authored-by: Mike Hardy <github@mikehardy.net>
  • Loading branch information
petetnt and mikehardy authored Dec 17, 2024
1 parent 3623a50 commit 6874d2e
Showing 1 changed file with 31 additions and 1 deletion.
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

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).

0 comments on commit 6874d2e

Please sign in to comment.