Skip to content

Commit 26ed916

Browse files
committed
2 parents 6d6efec + 87df9aa commit 26ed916

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

articles/communication-services/tutorials/add-chat-push-notifications.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Enable Push Notifications in your chat app
2+
title: Enable push notifications in your chat app
33
titleSuffix: An Azure Communication Services tutorial
44
description: Learn how to enable push notification in IOS App by using Azure Communication Chat SDK
55
author: angellan
@@ -14,10 +14,10 @@ ms.service: azure-communication-services
1414
# Enable Push Notifications in your chat app
1515

1616
>[!IMPORTANT]
17-
>This Push Notification feature is currently in public preview. Preview APIs and SDKs are provided without a service-level agreement, and are not recommended for production workloads. Certain features might not be supported or might have constrained capabilities.
17+
>This Push Notification feature is currently in public preview. Preview APIs and SDKs are provided without a service-level agreement, and aren't recommended for production workloads. Certain features might not be supported or might have constrained capabilities.
1818
1919
This tutorial will guide you to enable Push Notification in your IOS App by using Azure Communication Chat SDK.
20-
Push notifications alert clients of incoming messages in a chat thread in situations where the mobile app is not running in the foreground. Azure Communication Services supports two versions of push notifications.
20+
Push notifications alert clients of incoming messages in a chat thread in situations where the mobile app isn't running in the foreground. Azure Communication Services supports two versions of push notifications.
2121

2222
- `Basic Version` : The user will be able to see a badge number of 1 on the app’s icon, receive a notification sound and see a pop-up alert banner.
2323
- `Advanced Version`: Except for the features supported in basic version, the Contoso will be able to customize the title & message preview section in alert banner.
@@ -64,7 +64,7 @@ Here we recommend creating a .p12 APNS cert and set it in Notification Hub.
6464

6565
<img src="./media/add-chat-push-notification/cert-4.png" width="700" height="320" alt="Screenshot of APNS Cert Configuration step 3.">
6666

67-
* Step 4: Then you will be navigated to the below page. Here you will upload a Certificate Signing Request (CSR). Follow the next step to create a CSR.
67+
* Step 4: Then you're navigated to the below page. Here, you'll upload a Certificate Signing Request (CSR). Follow the next step to create a CSR.
6868

6969
<img src="./media/add-chat-push-notification/cert-5.png" width="700" height="400" alt="Screenshot of APNS Cert Configuration step 4.">
7070

@@ -101,40 +101,40 @@ Here we recommend creating a .p12 APNS cert and set it in Notification Hub.
101101

102102

103103
### 1 - Basic Version
104-
If you want to implement a basic version of Push Notification, you will need to register for remote notifications with APNS (Apple Push Notification Service). Please refer to [sample code](https://github.com/Azure-Samples/communication-services-ios-quickstarts/blob/main/add-chat-push-notifications/SwiftPushTest/AppDelegate.swift) to see the related implementation in `AppDelegate.swift`.
104+
If you want to implement a basic version of Push Notification, you need to register for remote notifications with APNS (Apple Push Notification Service). Refer to [sample code](https://github.com/Azure-Samples/communication-services-ios-quickstarts/blob/main/add-chat-push-notifications/SwiftPushTest/AppDelegate.swift) to see the related implementation in `AppDelegate.swift`.
105105

106106
### 2 - Advanced Version
107-
If you want to implement an advanced version of Push Notification, you will need to include the following items in your app. The reason is that we encrypt customer content (e.g. chat message content, sender display name, etc.) in push notification payload and it requires some workaround on your side.
107+
If you want to implement an advanced version of Push Notification, you need to include the following items in your app. The reason is that we encrypt customer content (e.g. chat message content, sender display name, etc.) in push notification payload and it requires some workaround on your side.
108108

109109
* Item 1: Data Storage for encryption keys
110110

111-
First, you should create a persistent data storage in IOS device. This data storage should be able to share data between Main App and App Extensions (Please refer to Item 2 for more information about App Extension – Notification Service Extension).
111+
First, you should create a persistent data storage in IOS device. This data storage should be able to share data between Main App and App Extensions (Refer to Item 2 for more information about App Extension – Notification Service Extension).
112112

113-
In our sample code, we will choose “App Group” as the data storage. Below are the suggested steps to create and use “App Group”:
113+
In our sample code, we'll choose “App Group” as the data storage. Below are the suggested steps to create and use “App Group”:
114114

115-
Follow the steps in [Add a capability](https://developer.apple.com/documentation/xcode/adding-capabilities-to-your-app?changes=latest_minor#Add-a-capability) to add the Apps Groups capability to your app’s targets – both Main App and Notification Service Extension (Please refer to Item 2 on how to create a Notification Service Extension).
115+
Follow the steps in [Add a capability](https://developer.apple.com/documentation/xcode/adding-capabilities-to-your-app?changes=latest_minor#Add-a-capability) to add the Apps Groups capability to your app’s targets – both Main App and Notification Service Extension (Refer to Item 2 on how to create a Notification Service Extension).
116116

117117
Also follow the steps in this [Apple official doc](https://developer.apple.com/documentation/xcode/configuring-app-groups?changes=latest_minor) to configure App Group. Make sure your Main App and App Extension have the same container name.
118118

119119
* Item 2: Notification Service Extension
120120

121121
Second, you should implement a “Notification Service Extension” bundled with main app. This is used for decrypting the push notification payload when receiving it.
122122

123-
Please go to this [Apple official doc](https://developer.apple.com/documentation/usernotifications/modifying_content_in_newly_delivered_notifications). Follow the step “Add a Service App Extension to your project” and “Implement Your Extension’s Handler Methods”.
123+
Go to this [Apple official doc](https://developer.apple.com/documentation/usernotifications/modifying_content_in_newly_delivered_notifications). Follow the step “Add a Service App Extension to your project” and “Implement Your Extension’s Handler Methods”.
124124

125-
Please notice that - in the step “Implement Your Extension’s Handler Methods”, Apple provides the sample code to decrypt data and we will follow the overall structure. However, since we use chat SDK for decryption, we will need to replace the part starting from `“// Try to decode the encrypted message data.”` with our customized logic. Please refer to the [sample code](https://github.com/Azure-Samples/communication-services-ios-quickstarts/blob/main/add-chat-push-notifications/SwiftPushTestNotificationExtension/NotificationService.swift) to see the related implementation in `NotificationService.swift`.
125+
Notice that in the step “Implement Your Extension’s Handler Methods,” Apple provides the sample code to decrypt data and we'll follow the overall structure. However, since we use chat SDK for decryption, we need to replace the part starting from `“// Try to decode the encrypted message data.”` with our customized logic. Refer to the [sample code](https://github.com/Azure-Samples/communication-services-ios-quickstarts/blob/main/add-chat-push-notifications/SwiftPushTestNotificationExtension/NotificationService.swift) to see the related implementation in `NotificationService.swift`.
126126

127127
* Item 3: Implementation of ChatClientPushNotificationProtocol
128128

129-
Third, `PushNotificationKeyHandler` is required for advanced version. As the SDK user, you could use the default `AppGroupPushNotificationKeyHandler` class provided by chat SDK to generate a key handler. If you don’t use `App Group` as the key storage or would like to customize key handling methods, please create your own class which conforms to PushNotificationKeyHandler protocol.
129+
Third, `PushNotificationKeyHandler` is required for advanced version. As the SDK user, you could use the default `AppGroupPushNotificationKeyHandler` class provided by chat SDK to generate a key handler. If you don’t use `App Group` as the key storage or would like to customize key handling methods, create your own class which conforms to PushNotificationKeyHandler protocol.
130130

131131
For PushNotificationKeyHandler, it defines two methods: `onPersistKey(encryptionKey:expiryTime)` and `onRetrieveKeys() -> [String]`.
132132

133133
The first method is used to persist the encryption key in the storage of user’s IOS device. Chat SDK will set 45 minutes as the expiry time of the encryption key. If you want Push Notification to be effect for more than 45 minutes, you need to schedule to call `chatClient.startPushNotifications(deviceToken:)` on a comparatively frequent basis (eg. every 15 minutes) so a new encryption key could be registered before the old key expires.
134134

135135
The second method is used to retrieve the valid keys previously stored. You have the flexibility to provide the customization based on the data storage (item 1) you choose.
136136

137-
In protocol extension, chat SDK provides the implementation of `decryptPayload(notification:) -> PushNotificationEvent` method which you can take advantage of. Please refer to the [sample code](https://github.com/Azure-Samples/communication-services-ios-quickstarts/blob/main/add-chat-push-notifications/SwiftPushTestNotificationExtension/NotificationService.swift) to see the related implementation in `NotificationService.swift`.
137+
In protocol extension, chat SDK provides the implementation of `decryptPayload(notification:) -> PushNotificationEvent` method which you can take advantage of. Refer to the [sample code](https://github.com/Azure-Samples/communication-services-ios-quickstarts/blob/main/add-chat-push-notifications/SwiftPushTestNotificationExtension/NotificationService.swift) to see the related implementation in `NotificationService.swift`.
138138

139139
## Testing
140140
1. Create a Chat Thread with User A and User B.

0 commit comments

Comments
 (0)