-
Notifications
You must be signed in to change notification settings - Fork 2
Setting up push notifications
The Khoros Community iOS SDK supports Apple Push Notification (APNs) and Firebase Cloud Messaging (FCM) for push notifications.
Ensure that your Community team has requested push notification enablement for your Community from askonboarding@lithium.com to request. Without enablement, you will not be able to complete the tasks in this guide.
This guide assumes:
For APNs:
- (APNs) You have enabled the Push Notification capability for your project in Xcode
- (APNs) You have created an authorization token signing key via your Apple Developer account to communicate with APNs
- (APNs) You have created your app configuration in Community Admin (See Getting Started with the Community iOS SDK)
For Firebase:
- (FCM) You have a Firebase project for your native Android app
- (FCM) You have connected the Firebase Console to Play Store Console
- (FCM) You have created your app configuration in Community Admin (See Getting Started with the Community iOS SDK)
Note: The Community iOS SDK supports token-based provider connection.
This section describes how to:
- Link APNs to Khoros Community
- Register your app to receive notifications
- Prepare to receive notifications
- Create alert text strings for your app
- Notification payload
To add your authentication token to Community Admin:
- Log into Community and open Community Admin > System > API Apps.
- Click Edit to edit your app configuration (or click Create if you have not yet set up your app in Community Admin).
- Select APNS from the Push Notification Adapter drop-down.
- Add the following:
- Push Notification Key ID - the APNS_KEY_ID found in the .p8 file generated from the APNs Auth Key page in your Apple Developer Center
- Push Notification Auth Key - the string value of APNS_AUTH_KEY in the .p8 file
- Push Notification Team ID - the TEAM_ID from the .p8 file
- Push Notification Topic ID - the bundle ID of your app
- Click Save.
APNs is now enabled for your Community integration.
See Apple's [UserNotifications guide] for instruction about how to configure support for remote notifications.
- Your app will ask to register with APNs
- Upon successful registration, APNs returns an app-specific device token to the user's device
- Your app sends the token to your notification server provider
Once you obtain the device token, pass the device token as a parameter while performing the login action, as follows:
LiSDKManager.shared().liAuthManager.initLoginFlow(from: self, deviceToken: "<your-device-token>", notificationProvider: NotificationProviders.apns)
On sign-out, the Khoros backend will clear the user's device token from its storage.
Create the following keys in your project's Localizable.strings
file for each language you support.
Key | Definition | Example |
---|---|---|
LiKudoAlertTitle | The title of the alert sent when a user receives kudos in the community | "LiKudoAlertTitle" = "You Got Kudos!"; |
LiKudoAlertBody | The body of the kudos alert | "LiKudoAlertBody" = "%@ kudoed your message"; |
LiMessageAlertTitle | The title of the alert sent when some replied to a user's post | "LiMessageAlertTitle" = "Reply"; |
LiMessageAlertBody | The body of the reply alert | "LiMessageAlertBody" = "%@ replied to your message"; |
LiSolutionAlertTitle | The title of the alert sent when a user's post is accepted as a solution | "LiSolutionAlertTitle" = "Solution accepted!"; |
LiSolutionAlertBody | The body of the accepted solution alert | "LiSolutionAlertBody" = "%@ accepted your post as a solution"; |
LiTopicAlertTitle | The title of the alert sent when a new topic message is posted to a board the user subscribes to. | "LiTopicAlertTitle" = "New Topic Posted"; |
LiTopicAlertBody | The body of the alert sent when a new topic message is posted to a board the user subscribes to. | "LiTopicAlertBody" = "%@ posted a new topic"; |
Community backend generates and sends the payload for you based on keys and arguments defined in a dictionary called aps
. The following table lists the title-loc-key
, loc-key
, and loc-args
required for each type of notification supported by the Community iOS SDK. Notice that title-loc-key
and loc-key
pull their value from the localized strings you created in Create alert text strings for your app.
Notification Type | title-loc-key | loc-key | loc-args |
---|---|---|---|
kudos | LiKudoAlertTitle | LiKudoAlertBody | Name of the person who gave the kudo |
messages | LiMessageAlertTitle | LiMessageAlertBody | Name of the person who replied to the message |
solutions | LiSolutionAlertTitle | LiSolutionAlertBody | Name of the person who accepted the message as a solution |
topic | LiTopicAlertTitle | LiTopicAlertBody | Name of the person who replied to the topic |
Here is an example aps
dictionary used for a Kudos alert. The source
, type
, message
, from
, and fromId
entries are Community app-specific data required by your app for the alert. The app-specific keys are the same for every notification type.
{
"aps" : {
"alert" : {
"title-loc-key": "LiKudoAlertTitle",
"loc-key" : "LiKudoAlertBody",
"loc-args" : ["John"]
}
},
"from": "userPro50S8szy",
"source": "community",
"type": "kudos",
"message": "{\"notificationType\":\"STANDARD\",\"eventTransactionId\":\"5acaac44-a818-4937-babf-025a9cd3f23b\",\"eventTimeUUID\":\"8594b270-cbea-11e7-891c-5254008bb56a\",\"eventSummary\":{\"subscriptionType\":\"KUDOS\",\"eventTransactionId\":\"5acaac44-a818-4937-babf-025a9cd3f23b\",\"eventTime\":1510959378199,\"kudoerId\":567,\"entityId\":749,\"entityKey\":\"message\",\"kudoWeight\":1}}",
"fromId": "567"
}
See the Firebase documentation to set up notifications. Their guides describe how to create the bridge between Firebase and your Community application so that Firebase directs notifications from Community to your native app. You'll need to generate a server key in Firebase and add that server key to Community Admin.
At this point, you have enabled Firebase push notifications for your Community integration. See the Firebase documentation for instructions to register for remote notifications and access registration tokens.