Skip to content

Commit 9097f8e

Browse files
docs(messaging): add instructions for images in ios notifications (#4225)
* docs(messaging, notifications-with-image): add instruction for Notification Extension * docs(messaging, notifications): add Podfile to spellcheck * docs(messaging, notifications): add newly created Notifications with Image page to the sidebar * chore(images): add assets folder for docs' images * chore(images): moving images into the 'static' folder * docs(messaging): reference images in the static folder Co-authored-by: Mike Hardy <[email protected]>
1 parent cfa56bd commit 9097f8e

File tree

8 files changed

+74
-2
lines changed

8 files changed

+74
-2
lines changed

.spellcheck.dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ OpenID
8484
perf
8585
performant
8686
personalization
87+
Podfile
8788
plist
8889
pre-fetched
8990
pre-rendered
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: iOS Notification Images
3+
description: Displaying an image in an iOS notification.
4+
next: /messaging/server-integration
5+
previous: /messaging/notifications
6+
---
7+
8+
This is a quick guide to display an image in an incoming notification. Android handles this out of the box so this extra setup is **only necessary for iOS**.
9+
10+
> If you want to know more about the specifics of this setup read the [official Firebase docs](https://firebase.google.com/docs/cloud-messaging/ios/send-image).
11+
12+
**🚨 Before you start**
13+
Be sure you already have Cloud Messaging installed and set up. In case you don't [get started here](/messaging/usage).
14+
15+
**🏁 Ready to start**
16+
The following steps will guide you through how to add a new target to your application to support payloads with an image. Open Xcode and let's get started.
17+
18+
### Step 1 - Add a notification service extension
19+
20+
- From Xcode top menu go to: **File > New > Target...**
21+
- A modal will present a list of possible targets, scroll down or use the filter to select `Notification Service Extension`. Press **Next**.
22+
- Add a product name (use `ImageNotification` to follow along) and click **Finish**
23+
- Enable the scheme by clicking **Activate**
24+
25+
![step-1](/assets/docs/messaging/ios-notification-images-step-1.gif)
26+
27+
### Step 2 - Add target to the Podfile
28+
29+
Ensure that your new extension has access to Firebase/Messaging pod by adding it in the Podfile:
30+
- From the Navigator open the Podfile: **Pods > Podfile**
31+
- Scroll down to the bottom of the file and add
32+
33+
```Ruby
34+
target 'ImageNotification' do
35+
pod 'Firebase/Messaging', '~> VERSION_NUMBER' # eg 6.31.0
36+
end
37+
```
38+
39+
- Make sure to change the version number `VERSION_NUMBER` with the currently installed version (check your Podfile.lock)
40+
- Install or update your pods using `pod install` from the `ios` folder
41+
42+
![step-2](/assets/docs/messaging/ios-notification-images-step-2.gif)
43+
44+
### Step 3 - Use the extension helper
45+
46+
At this point everything should still be running normally. This is the final step which is invoking the extension helper.
47+
- From the navigator select your `ImageNotification` extension
48+
- Open the `NotificationService.m` file
49+
- At the top of the file import `FirebaseMessaging.h` right after the `NotificationService.h` as shown below
50+
51+
```diff
52+
#import "NotificationService.h"
53+
+ #import "FirebaseMessaging.h"
54+
```
55+
56+
- then replace everything from line 25 to 28 with the extension helper
57+
58+
```diff
59+
- // Modify the notification content here...
60+
- self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
61+
62+
- self.contentHandler(self.bestAttemptContent);
63+
+ [[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent withContentHandler:contentHandler];
64+
```
65+
66+
![step-3](/assets/docs/messaging/ios-notification-images-step-3.gif)
67+
68+
## All done
69+
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).

docs/messaging/notifications.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Notifications
33
description: Displaying & handling notifications from FCM.
4-
next: /messaging/server-integration
4+
next: /messaging/ios-notification-images
55
previous: /messaging/ios-permissions
66
---
77

docs/messaging/server-integration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Server Integration
33
description: Integrate Firebase Cloud Messaging with your backend server.
44
next: /storage/usage
5-
previous: /messaging/notifications
5+
previous: /messaging/ios-notification-images
66
---
77

88
The Cloud Messaging module provides the tools required to enable you to send custom messages directly from your own servers.

docs/sidebar.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
- '/messaging/ios-permissions'
6363
- - Notifications
6464
- '/messaging/notifications'
65+
- - iOS Notification Images
66+
- '/messaging/ios-notification-images'
6567
- - Server Integration
6668
- '/messaging/server-integration'
6769
- '//static.invertase.io/assets/firebase/cloud-messaging.svg'
836 KB
Loading
561 KB
Loading
1.12 MB
Loading

0 commit comments

Comments
 (0)