Skip to content

Commit 6874d2e

Browse files
petetntmikehardy
andauthored
docs: create a Swift version example of the ios-notification-images doc (#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 <[email protected]>
1 parent 3623a50 commit 6874d2e

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

docs/messaging/ios-notification-images.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ end
4343

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

46-
### Step 3 - Use the extension helper
46+
### Step 3 - Use the extension helper (Objective-C)
47+
48+
> If you selected to create your extension as a Swift project, jump to the next section.
4749
4850
At this point everything should still be running normally. This is the final step which is invoking the extension helper.
4951

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

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

73+
### Step 3 - Use the extension helper (Swift)
74+
75+
At this point everything should still be running normally. This is the final step which is invoking the extension helper.
76+
77+
- From the navigator select your `ImageNotification` extension
78+
- Open the `NotificationService.swift` file
79+
- At the top of the file import `Firebase` right after the `NotificationService` as shown below
80+
81+
```diff
82+
import UserNotifications
83+
+ import Firebase
84+
85+
class NotificationService: UNNotificationServiceExtension {
86+
```
87+
88+
- then replace everything from line 19 to 23 with the extension helper
89+
90+
```diff
91+
if let bestAttemptContent = bestAttemptContent {
92+
- // Modify the notification content here...
93+
- bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
94+
-
95+
- contentHandler(bestAttemptContent)
96+
+ Messaging.serviceExtension()
97+
+ .populateNotificationContent(bestAttemptContent, withContentHandler: contentHandler)
98+
}
99+
```
100+
71101
## All done
72102

73103
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 commit comments

Comments
 (0)