Push Notification
#
OverviewWe use APNS services to receive messages in background.
#
PrerequisitesPlease upload your APNS and VOIP Certificate to our Console. To know more how to generate and upload APNS and VOIP Certificate Click Here
In your Appdelegate, register for remote notification by conforming to the delegates UNUserNotificationCenterDelegate
.
Call the below methods when an APNS token gets updated.
Argument | Description |
---|---|
TOKEN | Apns Token |
#
CapabilitiesTo receive push notification in the background or in the killed state, You need to enable below capabilities.
Capabilities |
---|
Background Modes |
Now, go to the background mode and enable the below given modes
Background Modes |
---|
Remote notifications |
#
App Group IdTo receive messages in the background or in the killed state, You need to enable app group container ID.
In order to access data between app and notification extension, enabling app group is mandatory to access user defaults and database in container.
#
Process push notification request We have to set CONTAINER_ID
in Appdeleagte
class.
In function didFinishLaunchingWithOptions use this ChatManager.setAppGroupContainerId(id: CONTAINER_ID)
method to set CONTAINER_ID which is your App Group
string name
#
Parameter DescriptionFunction | Parameter Type | Description |
---|---|---|
CONTAINER_ID | String | Create App groups and assign the obtained group container id. SDK uses this string to create the path for the local storage. |
caution
Changing existing app group container may cause data loss.
As a process of getting push notification in background and Killed state, the SDK require to add Notification Extension service
in your Xcode project.
Notification service extension can be acts as a mediator between the User Interface and the APNS. Like all other iOS extensions, such an extension can simply be added to the app in the form of another target.
#
Step 1Create NotificationExtension Target
You can see New target and NotificationService folder been created in your project.
#
Step 2Add MirrorflySDK
to the new target created for NotificationExtension in Podfile
#
Step 3Do Pod install
#
Step 4Start using the SDK using the below statement
#
Step 5Re-initialize the ChatSDK method and setAppGroupContainerId method inside func didReceive
method of the UNNotificationServiceExtension
delegate.
In class that extends the UNNotificationServiceExtension
call the above NotificationMessageSupport.shared.didReceiveNotificationRequest
method to process the request further.
Argument | Type | Description |
---|---|---|
NOTIFICATION_CONTENT | UNMutableNotificationContent | Notification request content |
COMPLETION_BLOCK | (UNMutableNotificationContent?, ChatMessage?) -> Void | Completion Block |