You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docusaurus/docs/iOS/guides/push-notifications.md
+71-19
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Push Notifications
3
3
---
4
4
5
-
Push notifications can be configured to receive updates when the application is closed or on the background. Stream Chat sends push notification to channel members that are not online and have at least one registered device. Stream supports both **Certificate-based provider connection trust (.p12 certificate)** and **Token-based provider connection trust (JWT)**. Token-based authentication is the preferred way to configure push notifications.
5
+
Push notifications can be configured to receive updates when the application is closed or on the background. Stream Chat sends push notification to channel members that are not online and have at least one registered device. Stream supports **Token-based provider connection trust (JWT)**.
6
6
7
7
:::note
8
8
You can find more on setting up push [here](https://getstream.io/chat/docs/ios-swift/push_introduction/?language=swift). Make sure you've taken care of authentication before proceeding to the next steps.
@@ -12,7 +12,7 @@ You can find more on setting up push [here](https://getstream.io/chat/docs/ios-s
12
12
13
13
To receive push notifications from the Stream server the first step you need to do is register the device. To do this you need to call `UIApplication.shared.registerForRemoteNotifications()` and send the token from `application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)`.
14
14
15
-
Here is the boilerplate code that you can add to your `AppDelegate`:
15
+
Here is the code that you can add to your `AppDelegate`:
16
16
17
17
```swift
18
18
funcapplication(
@@ -32,7 +32,7 @@ func application(
32
32
}
33
33
```
34
34
35
-
Because devices are linked to chat users, you should request the device token in the `connectUser` completion block
35
+
Because devices are linked to chat users, you should request the device token once the your user is successfully connected to Chat.
If you're interested in leveraging different push configurations per each build type of your app (eg `AppStore`, `Staging`) or similar, you can do so via adding the new `multi-bundle` push configuration in `Push Notifications` tab in your Stream Dashboard.
You can add new multi-bundle configuration by tapping on `New Configuration` under `Push Notifications` tab and by selecting your preferred push notification provider (eg. `APN`, `Firebase`, ..).
68
+
69
+
Once created, fill in the following details:
70
+
*`Name of your configuration` - this name will be used in `addDevice` registration call.
71
+
*`Bundle/Topic ID` - bundle identifier of your app.
and `enable` the push configuration by tapping `Enabled` toggle on top right.
77
+
Once done, save the new push configuration.
78
+
79
+
Following example shows how to register your device for given APN push configuration in your app.
80
+
81
+
```swift
82
+
funcapplication(
83
+
_application: UIApplication,
84
+
didRegisterForRemoteNotificationsWithDeviceTokendeviceToken: Data
85
+
) {
86
+
guard ChatClient.shared.currentUserId !=nilelse {
87
+
log.warning("cannot add the device without connecting as user first, did you call connectUser")
88
+
return
89
+
}
90
+
91
+
/// Specify `providerName:` parameter.
92
+
ChatClient.shared.currentUserController().addDevice(.apn(token: deviceToken, providerName: "Name of your configuration")) { error in
93
+
iflet error = error {
94
+
log.warning("adding a device failed with an error \(error)")
95
+
}
96
+
}
97
+
}
98
+
```
99
+
100
+
:::note
101
+
`providerName` can be specified only for the push configurations containing the `multi-bundle` badge. If you do not leverage `multi-bundle` setup, leave the `providerName` parameter empty.
Push notifications can be tricky to setup correctly. Make sure to set up [logging](https://getstream.io/chat/docs/ios-swift/push_logs/?language=swift) and check for errors and settings on the [Dashboard](https://getstream.io/dashboard/) and refer to our debugging tips for [common error scenarios](https://getstream.io/chat/docs/ios-swift/push_-_common_issues_and_faq/?language=swift).
109
+
Push notifications can be tricky to setup correctly.
64
110
111
+
Here's few articles that might help to troubleshoot your issues:
112
+
*[Sending Push Notifications Using Command-Line Tools (developer.apple.com)](https://developer.apple.com/documentation/usernotifications/sending_push_notifications_using_command-line_tools).
113
+
*[Set up logging on Stream Dashboard](https://getstream.io/chat/docs/ios-swift/push_logs/?language=swift)
114
+
*[Check for errors and settings on the Dashboard](https://getstream.io/dashboard/) and refer to our debugging tips for [common error scenarios](https://getstream.io/chat/docs/ios-swift/push_-_common_issues_and_faq/?language=swift).
65
115
:::
66
116
67
117
### Removing devices
68
118
119
+
Usually, you might want to deregister the user's device from push notifications when logging the user out from the Chat.
@@ -78,9 +130,9 @@ ChatClient.shared.currentUserController().removeDevice(id: deviceId) { error in
78
130
}
79
131
```
80
132
81
-
### Redirecting From Notification To App
133
+
### Redirecting From Remote Push Notification To App
82
134
83
-
In order to redirect the user from notifications to a specific screen in your app, you need to create a `UNUserNotificationCenterDelegate`, your delegate will be called when the app is open from a push notification.
135
+
In order to redirect the user from push notification to a specific screen in your app, you need to create a `UNUserNotificationCenterDelegate`. Your delegate will be called when the app is opened from a push notification.
84
136
85
137
The following code shows how to open the app on the channel after tapping on the push notification:
86
138
@@ -110,11 +162,11 @@ class SampleNotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
guardlet scene = scene as? UIWindowScene else { return }
151
203
let window =UIWindow(windowScene: scene)
152
-
204
+
153
205
guardlet navigationController =UIStoryboard(
154
206
name: "Main",
155
207
bundle: nil
@@ -165,11 +217,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
165
217
166
218
}
167
219
```
168
-
## Customizing Push Notifications
220
+
## Customising Remote Push Notifications
169
221
170
-
Stream sends push notifications ready for iOS to be presented to the user. If you followed this document until now, you app is already receiving clear messages via push notifications.
222
+
Stream sends remote push notifications ready for iOS to be presented to the user. If you followed this document until now, your app is already receiving clear messages via push notifications.
171
223
172
-
In many cases you want the push message to be customized, the best way to do this is via a service extension. A service extension will capture all notifications and allows you to modify its content before presenting it to the user.
224
+
In caseyou need to customise the UI of the received push notification, the best way to do this is via a service extension. A service extension will capture all notifications and allows you to modify its content before presenting it to the user.
173
225
174
226
### Notification Service Extension
175
227
@@ -228,7 +280,7 @@ class NotificationService: UNNotificationServiceExtension {
228
280
contentHandler(content)
229
281
}
230
282
}
231
-
283
+
232
284
overridefuncserviceExtensionTimeWillExpire() {
233
285
// Called just before the extension will be terminated by the system.
234
286
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
@@ -241,7 +293,7 @@ class NotificationService: UNNotificationServiceExtension {
241
293
Let's summarize the most important steps:
242
294
243
295
- The `ChatClient` is initialized with Api Key and Token, `connectUser` must not be used in a service extension
244
-
- `chatHandler.handleNotification` completion block receives a `ChatPushNotificationContent`
296
+
- `chatHandler.handleNotification` completion block receives a `ChatPushNotificationContent`
245
297
- `ChatPushNotificationContent` is handled for the message case, in that case it will contain a regular `ChatMessage` model
246
298
247
299
#### Complete Example
@@ -270,13 +322,13 @@ class NotificationService: UNNotificationServiceExtension {
0 commit comments