From 60d941f6fa2676d59c6e96f61a6fb4b7eb424cf4 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Sat, 3 Jun 2017 10:25:23 -0400 Subject: [PATCH] remove warning --- ios/RNFIRMessaging.h | 5 +-- ios/RNFIRMessaging.m | 35 ++++++++++---------- ios/RNFIRMessaging.xcodeproj/project.pbxproj | 6 ++-- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/ios/RNFIRMessaging.h b/ios/RNFIRMessaging.h index 0a07e04..9f741a2 100644 --- a/ios/RNFIRMessaging.h +++ b/ios/RNFIRMessaging.h @@ -2,12 +2,13 @@ #import #import +#import -#import +#import @import UserNotifications; -@interface RNFIRMessaging : NSObject +@interface RNFIRMessaging : RCTEventEmitter typedef void (^RCTRemoteNotificationCallback)(UIBackgroundFetchResult result); typedef void (^RCTWillPresentNotificationCallback)(UNNotificationPresentationOptions result); diff --git a/ios/RNFIRMessaging.m b/ios/RNFIRMessaging.m index 24f41fd..b7e2c58 100644 --- a/ios/RNFIRMessaging.m +++ b/ios/RNFIRMessaging.m @@ -1,11 +1,9 @@ #import "RNFIRMessaging.h" #import -#import #import @import UserNotifications; -#import #import #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0 @@ -134,9 +132,8 @@ RCT_ENUM_CONVERTER(UNNotificationPresentationOptions, (@{ @implementation RNFIRMessaging -RCT_EXPORT_MODULE() - @synthesize bridge = _bridge; +RCT_EXPORT_MODULE(); + (void)didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull RCTRemoteNotificationCallback)completionHandler { NSMutableDictionary* data = [[NSMutableDictionary alloc] initWithDictionary: userInfo]; @@ -228,7 +225,8 @@ RCT_EXPORT_MODULE() NSLog(@"Disconnected from FCM"); } -RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject){ +RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve) +{ UILocalNotification *localUserInfo = _bridge.launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]; if (localUserInfo) { resolve([[localUserInfo userInfo] copy]); @@ -237,17 +235,17 @@ RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve rejecte resolve([_bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] copy]); } -RCT_EXPORT_METHOD(getFCMToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) +RCT_EXPORT_METHOD(getFCMToken:(RCTPromiseResolveBlock)resolve) { resolve([[FIRInstanceID instanceID] token]); } - (void) onTokenRefresh { - [_bridge.eventDispatcher sendDeviceEventWithName:@"FCMTokenRefreshed" body:[[FIRInstanceID instanceID] token]]; + [self sendEventWithName:@"FCMTokenRefreshed" body:[[FIRInstanceID instanceID] token]]; } -RCT_EXPORT_METHOD(requestPermissions) +RCT_EXPORT_METHOD(requestPermissions:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { if (RCTRunningInAppExtension()) { return; @@ -261,9 +259,6 @@ RCT_EXPORT_METHOD(requestPermissions) UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:(NSUInteger)allNotificationTypes categories:nil]; [app registerUserNotificationSettings:notificationSettings]; - } else { - //iOS 7 or below - [app registerForRemoteNotificationTypes:(NSUInteger)allNotificationTypes]; } } else { // iOS 10 or later @@ -275,6 +270,11 @@ RCT_EXPORT_METHOD(requestPermissions) [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) { + if(granted){ + resolve(nil); + } else{ + reject(@"notification_error", @"Failed to grand permission", error); + } } ]; #endif @@ -295,7 +295,7 @@ RCT_EXPORT_METHOD(unsubscribeFromTopic: (NSString*) topic) // Receive data message on iOS 10 devices. - (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage { - [_bridge.eventDispatcher sendDeviceEventWithName:FCMNotificationReceived body:[remoteMessage appData]]; + [self sendEventWithName:FCMNotificationReceived body:[remoteMessage appData]]; } RCT_EXPORT_METHOD(presentLocalNotification:(id)data resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) @@ -373,14 +373,13 @@ RCT_EXPORT_METHOD(cancelLocalNotification:(NSString*) notificationId) } } -RCT_EXPORT_METHOD(getScheduledLocalNotifications:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) +RCT_EXPORT_METHOD(getScheduledLocalNotifications:(RCTPromiseResolveBlock)resolve) { if([UNUserNotificationCenter currentNotificationCenter] != nil){ [[UNUserNotificationCenter currentNotificationCenter] getPendingNotificationRequestsWithCompletionHandler:^(NSArray * _Nonnull requests) { NSMutableArray* list = [[NSMutableArray alloc] init]; for(UNNotificationRequest * notif in requests){ - NSString* interval; - UNMutableNotificationContent *content = notif.content; + UNNotificationContent *content = notif.content; [list addObject:content.userInfo]; } resolve(list); @@ -396,10 +395,10 @@ RCT_EXPORT_METHOD(getScheduledLocalNotifications:(RCTPromiseResolveBlock)resolve RCT_EXPORT_METHOD(setBadgeNumber: (NSInteger*) number) { - [RCTSharedApplication() setApplicationIconBadgeNumber:number]; + [RCTSharedApplication() setApplicationIconBadgeNumber:*number]; } -RCT_EXPORT_METHOD(getBadgeNumber: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) +RCT_EXPORT_METHOD(getBadgeNumber: (RCTPromiseResolveBlock)resolve) { resolve(@([RCTSharedApplication() applicationIconBadgeNumber])); } @@ -467,7 +466,7 @@ RCT_EXPORT_METHOD(finishNotificationResponse: (NSString *)completionHandlerId){ data[@"_completionHandlerId"] = completionHandlerId; } - [_bridge.eventDispatcher sendDeviceEventWithName:FCMNotificationReceived body:data]; + [self sendEventWithName:FCMNotificationReceived body:data]; } diff --git a/ios/RNFIRMessaging.xcodeproj/project.pbxproj b/ios/RNFIRMessaging.xcodeproj/project.pbxproj index 5df0e87..4b366c5 100644 --- a/ios/RNFIRMessaging.xcodeproj/project.pbxproj +++ b/ios/RNFIRMessaging.xcodeproj/project.pbxproj @@ -153,13 +153,14 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; WARNING_CFLAGS = ( "-Wextra", "-Wall", + "-Wno-semicolon-before-method-body", ); }; name = Debug; @@ -194,13 +195,14 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; WARNING_CFLAGS = ( "-Wextra", "-Wall", + "-Wno-semicolon-before-method-body", ); }; name = Release; -- 2.26.2