Push notification
Push Notification setup
Android
Create your app on firebase and download the google-services.json file: https://console.firebase.google.com/project
Copy the firebase server key and add it in Kommunicate dashboard under Developer -> Push notifications -> Android -> FCM/GCM Key
Download the google-services.json file from firebase dashboard and paste it under your project/android/app/ directory
Copy the KmFirebaseService file from here and paste it in your project's java directory project/android/app/src/main/java/
Add the below configurations in your AndroidManifest.xml file inside the <application tag:
<service
android:name="com.getcapacitor.CapacitorFirebaseMessagingService"
tools:node="remove" />
<service
android:name="com.applozic.mobicomkit.uiwidgets.KmFirebaseMessagingService"
tools:node="remove" />
<service
android:name=".KmFirebaseService"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
- Add the below entry inside the <manifest tag in your AndroidManifest.xml file:
xmlns:tools="http://schemas.android.com/tools"
iOs
Generate your debug and production certificates from your apple developer account and upload on Kommunicate dashboard.
Follow the steps from here to upload the certificates and add notification capabilities: https://docs.kommunicate.io/docs/ios-pushnotification#certificates
Download the KommunicateWrapper.swift file from here
Add the KommunicateWrapper.swift file to the project target. Click on
-> Add files to 'YourProject' -> Select the downloaded KommunicateWrapper.swift file Do the below changes in your AppDelgate.swift file: a. Add import for UserNotifications:
import UserNotifications
b. implement the UNUserNotificationCenterDelegate:
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
c. Call the KommunicateWrapper methods in the respective AppDelegate methods as below:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UNUserNotificationCenter.current().delegate = self
KommunicateWrapper.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
KommunicateWrapper.shared.userNotificationCenter(center, willPresent: notification, withCompletionHandler: { options in
completionHandler(options)
})
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
KommunicateWrapper.shared.userNotificationCenter(center, didReceive: response, withCompletionHandler: {
completionHandler()
})
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
KommunicateWrapper.shared.applicationDidEnterBackground(application: application)
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
KommunicateWrapper.shared.applicationWillEnterForeground(application: application)
UIApplication.shared.applicationIconBadgeNumber = 0
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
KommunicateWrapper.shared.applicationWillTerminate(application: application)
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: deviceToken)
print("DEVICE_TOKEN_DATA :: \(deviceToken.description)") // (SWIFT = 3) : TOKEN PARSING
KommunicateWrapper.shared.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}