Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "com_test_pushfcmpush_NativeClassCodeImpl.h"
- #import <FirebaseCore/FIRApp.h>
- #import <FirebaseMessaging/FIRMessaging.h>
- #import <Firebase/Firebase.h>
- @interface com_test_pushfcmpush_NativeClassCodeImpl () <UNUserNotificationCenterDelegate>@end
- @implementation com_test_pushfcmpush_NativeClassCodeImpl
- NSString *const kGCMMessageIDKey = @"gcm.message_id";
- -(void)initFcm{
- }
- -(BOOL)isSupported{
- return YES;
- }
- // [START receive_message]
- - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
- // If you are receiving a notification message while your app is in the background,
- // this callback will not be fired till the user taps on the notification launching the application.
- // TODO: Handle data of notification
- // With swizzling disabled you must let Messaging know about the message, for Analytics
- // [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
- // Print message ID.
- if (userInfo[kGCMMessageIDKey]) {
- NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
- }
- // Print full message.
- NSLog(@"%@", userInfo);
- }
- - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
- fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
- // If you are receiving a notification message while your app is in the background,
- // this callback will not be fired till the user taps on the notification launching the application.
- // TODO: Handle data of notification
- // With swizzling disabled you must let Messaging know about the message, for Analytics
- // [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
- // Print message ID.
- if (userInfo[kGCMMessageIDKey]) {
- NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
- }
- // Print full message.
- NSLog(@"%@", userInfo);
- completionHandler(UIBackgroundFetchResultNewData);
- }
- // [END receive_message]
- // [START ios_10_message_handling]
- // Receive displayed notifications for iOS 10 devices.
- // Handle incoming notification messages while app is in the foreground.
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center
- willPresentNotification:(UNNotification *)notification
- withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
- NSDictionary *userInfo = notification.request.content.userInfo;
- // With swizzling disabled you must let Messaging know about the message, for Analytics
- // [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
- // Print message ID.
- if (userInfo[kGCMMessageIDKey]) {
- NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
- }
- // Print full message.
- NSLog(@"%@", userInfo);
- // Change this to your preferred presentation option
- completionHandler(UNNotificationPresentationOptionNone);
- }
- // Handle notification messages after display notification is tapped by the user.
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center
- didReceiveNotificationResponse:(UNNotificationResponse *)response
- withCompletionHandler:(void(^)(void))completionHandler {
- NSDictionary *userInfo = response.notification.request.content.userInfo;
- if (userInfo[kGCMMessageIDKey]) {
- NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
- }
- // Print full message.
- NSLog(@"%@", userInfo);
- completionHandler();
- }
- // [END ios_10_message_handling]
- // [START refresh_token]
- - (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken {
- NSLog(@"FCM registration token: %@", fcmToken);
- // Notify about received token.
- NSDictionary *dataDict = [NSDictionary dictionaryWithObject:fcmToken forKey:@"token"];
- [[NSNotificationCenter defaultCenter] postNotificationName:
- @"FCMToken" object:nil userInfo:dataDict];
- // TODO: If necessary send token to application server.
- // Note: This callback is fired at each app startup and whenever a new token is generated.
- }
- // [END refresh_token]
- // [START ios_10_data_message]
- // Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground.
- // To enable direct data messages, you can set [Messaging messaging].shouldEstablishDirectChannel to YES.
- - (void)messaging:(FIRMessaging *)messaging didReceiveMessage:(FIRMessagingRemoteMessage *)remoteMessage {
- NSLog(@"Received data message: %@", remoteMessage.appData);
- }
- // [END ios_10_data_message]
- - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
- NSLog(@"Unable to register for remote notifications: %@", error);
- }
- // This function is added here only for debugging purposes, and can be removed if swizzling is enabled.
- // If swizzling is disabled then this function must be implemented so that the APNs device token can be paired to
- // the FCM registration token.
- - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
- NSLog(@"APNs device token retrieved: %@", deviceToken);
- // With swizzling disabled you must set the APNs device token here.
- // [FIRMessaging messaging].APNSToken = deviceToken;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement