If you want to retrieve the notification payload sent to the device, you can use the following methods in the AppDelegate class. Netmera swizzles iOS methods.
UNUserNotificationCenter
Netmera SDK automatically collects Click Push Events. However, if you have issues with collection of this event make sure the following UNUserNotificationCenter
method is placed at the top line in didFinishLaunchingWithOptions
. This configuration ensures click events on notifications are processed correctly.
Implement UNUserNotificationCenter in didFinishLaunchingWithOptions
Insert the code below at the beginning of didFinishLaunchingWithOptions
in your app’s AppDelegate
file:
Swift Objective-C
Copy //in didFinishLaunchingWithOptions
if #available ( iOS 10.0 , * ) {
UNUserNotificationCenter. current () .delegate = self as? UNUserNotificationCenterDelegate
} else {
// Fallback on earlier versions
}
This method should be placed at the beginning (top line) of the didFinishLaunchingWithOptions
method in your app’s AppDelegate
file.
Copy //in didFinishLaunchingWithOptions
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
This method should be placed at the beginning (top line) of the didFinishLaunchingWithOptions
method in your app’s AppDelegate
file.
Push Payload for Push Click
This method is used to take the push payload when the push notification is clicked.
Swift Objective-C
Copy func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
{
//NetmeraPushObject(dictionary: response.notification.request.content.userInfo)
//object.alert.body //Push Text
//object.alert.title //Push Title
//object.action.deeplinkURL //Push Deeplink
//object.customDictionary //Custom JSON
}
Copy -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
//NetmeraPushObject *object = [[NetmeraPushObject alloc] initWithDictionary:response.notification.request.content.userInfo];
//object.alert.body //Push Text
//object.alert.title //Push Title
//object.action.deeplinkURL //Push Deeplink
//object.customDictionary //Custom JSON
}
Push Payload for Push Received
Take push payload for push received. This method will return latest push object received by device.
Swift Objective-C
Copy func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
{
//Netmera.recentPushObject()?.alert.body //Push Text
//Netmera.recentPushObject()?.alert.title //Push Title
//Netmera.recentPushObject()?.action.deeplinkURL //Push Deeplink
//Netmera.recentPushObject()?.customDictionary //Custom JSON
}
Copy -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//[Netmera recentPushObject].alert.body //Push Text
//[Netmera recentPushObject].alert.title //Push Title
//[Netmera recentPushObject].action.deeplinkURL //Push Deeplink
//[Netmera recentPushObject].customDictionary //Custom JSON
}
Push Payload for Push Received on Application Foreground
Take push payload for push Received on application foreground.
Swift Objective-C
Copy func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler ( .alert )
}
Copy - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
completionHandler(UNNotificationPresentationOptionAlert);
}
Take Push Token Method
Swift Objective-C
Copy func application ( _ application : UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken : Data)
{}
Copy - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{}