Skip to content

Instantly share code, notes, and snippets.

@flurrydev
Created October 10, 2018 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flurrydev/d5ec399e0e7b88aa9e549e93ccba8be0 to your computer and use it in GitHub Desktop.
Save flurrydev/d5ec399e0e7b88aa9e549e93ccba8be0 to your computer and use it in GitHub Desktop.
Log notification received & clicked (Obj-C)
// tells the app that a remote notification arrived that indicates there is data to be fetched.
// ios 7+ prior to UNUserNotificationCenter
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler {
// check if the notification is from Flurry
if ([FlurryMessaging isFlurryMsg:userInfo]) {
[FlurryMessaging receivedRemoteNotification:userInfo withCompletionHandler:^{
completionHandler(UIBackgroundFetchResultNewData);
}];
}
}
// Process and handle the user's response to a delivered notification.
// ios 10+ UNUserNotificationCenterDelegate method
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){
if ([FlurryMessaging isFlurryMsg:response.notification.request.content.userInfo]) {
[FlurryMessaging receivedNotificationResponse:response withCompletionHandler:^{
completionHandler();
// ... add your handling here
}];
}
}
// present user an alert if app is in foreground when a notification is coming
// ios 10+ UNUserNotificationCenterDelegate mehod
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
if ([FlurryMessaging isFlurryMsg:notification.request.content.userInfo]) {
[FlurryMessaging presentNotification:notification withCompletionHandler:^{
// present user an alert if app is in foreground when a notification is coming
completionHandler(UNNotificationPresentationOptionAlert);
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment