Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. #import "com_test_pushfcmpush_NativeClassCodeImpl.h"
  2. #import <FirebaseCore/FIRApp.h>
  3. #import <FirebaseMessaging/FIRMessaging.h>
  4. #import <Firebase/Firebase.h>
  5.  
  6.  
  7. @interface com_test_pushfcmpush_NativeClassCodeImpl () <UNUserNotificationCenterDelegate>@end
  8.  
  9. @implementation com_test_pushfcmpush_NativeClassCodeImpl
  10.  
  11. NSString *const kGCMMessageIDKey = @"gcm.message_id";
  12.  
  13. -(void)initFcm{
  14. }
  15.  
  16. -(BOOL)isSupported{
  17. return YES;
  18. }
  19.  
  20.  
  21.  
  22. // [START receive_message]
  23. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  24. // If you are receiving a notification message while your app is in the background,
  25. // this callback will not be fired till the user taps on the notification launching the application.
  26. // TODO: Handle data of notification
  27.  
  28. // With swizzling disabled you must let Messaging know about the message, for Analytics
  29. // [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
  30.  
  31. // Print message ID.
  32. if (userInfo[kGCMMessageIDKey]) {
  33. NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
  34. }
  35.  
  36. // Print full message.
  37. NSLog(@"%@", userInfo);
  38. }
  39.  
  40. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
  41. fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  42. // If you are receiving a notification message while your app is in the background,
  43. // this callback will not be fired till the user taps on the notification launching the application.
  44. // TODO: Handle data of notification
  45.  
  46. // With swizzling disabled you must let Messaging know about the message, for Analytics
  47. // [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
  48.  
  49. // Print message ID.
  50. if (userInfo[kGCMMessageIDKey]) {
  51. NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
  52. }
  53.  
  54. // Print full message.
  55. NSLog(@"%@", userInfo);
  56.  
  57. completionHandler(UIBackgroundFetchResultNewData);
  58. }
  59. // [END receive_message]
  60.  
  61. // [START ios_10_message_handling]
  62. // Receive displayed notifications for iOS 10 devices.
  63. // Handle incoming notification messages while app is in the foreground.
  64. - (void)userNotificationCenter:(UNUserNotificationCenter *)center
  65. willPresentNotification:(UNNotification *)notification
  66. withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  67. NSDictionary *userInfo = notification.request.content.userInfo;
  68.  
  69. // With swizzling disabled you must let Messaging know about the message, for Analytics
  70. // [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
  71.  
  72. // Print message ID.
  73. if (userInfo[kGCMMessageIDKey]) {
  74. NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
  75. }
  76.  
  77. // Print full message.
  78. NSLog(@"%@", userInfo);
  79.  
  80. // Change this to your preferred presentation option
  81. completionHandler(UNNotificationPresentationOptionNone);
  82. }
  83.  
  84. // Handle notification messages after display notification is tapped by the user.
  85. - (void)userNotificationCenter:(UNUserNotificationCenter *)center
  86. didReceiveNotificationResponse:(UNNotificationResponse *)response
  87. withCompletionHandler:(void(^)(void))completionHandler {
  88. NSDictionary *userInfo = response.notification.request.content.userInfo;
  89. if (userInfo[kGCMMessageIDKey]) {
  90. NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
  91. }
  92.  
  93. // Print full message.
  94. NSLog(@"%@", userInfo);
  95.  
  96. completionHandler();
  97. }
  98.  
  99. // [END ios_10_message_handling]
  100.  
  101. // [START refresh_token]
  102. - (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken {
  103. NSLog(@"FCM registration token: %@", fcmToken);
  104. // Notify about received token.
  105. NSDictionary *dataDict = [NSDictionary dictionaryWithObject:fcmToken forKey:@"token"];
  106. [[NSNotificationCenter defaultCenter] postNotificationName:
  107. @"FCMToken" object:nil userInfo:dataDict];
  108. // TODO: If necessary send token to application server.
  109. // Note: This callback is fired at each app startup and whenever a new token is generated.
  110. }
  111. // [END refresh_token]
  112.  
  113. // [START ios_10_data_message]
  114. // Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground.
  115. // To enable direct data messages, you can set [Messaging messaging].shouldEstablishDirectChannel to YES.
  116. - (void)messaging:(FIRMessaging *)messaging didReceiveMessage:(FIRMessagingRemoteMessage *)remoteMessage {
  117. NSLog(@"Received data message: %@", remoteMessage.appData);
  118. }
  119. // [END ios_10_data_message]
  120.  
  121. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  122. NSLog(@"Unable to register for remote notifications: %@", error);
  123. }
  124.  
  125. // This function is added here only for debugging purposes, and can be removed if swizzling is enabled.
  126. // If swizzling is disabled then this function must be implemented so that the APNs device token can be paired to
  127. // the FCM registration token.
  128. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  129. NSLog(@"APNs device token retrieved: %@", deviceToken);
  130.  
  131. // With swizzling disabled you must set the APNs device token here.
  132. // [FIRMessaging messaging].APNSToken = deviceToken;
  133. }
  134.  
  135. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement