Created
October 10, 2018 20:33
-
-
Save flurrydev/d5ec399e0e7b88aa9e549e93ccba8be0 to your computer and use it in GitHub Desktop.
Log notification received & clicked (Obj-C)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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