Add a promise response to iOS messaging requestPermissions to return permission popup response (iOS 10+)

This commit is contained in:
Chris Bianca 2017-03-27 12:51:52 +01:00
parent 187f7cd7b9
commit 43df6b5564
1 changed files with 6 additions and 2 deletions

View File

@ -247,7 +247,7 @@ RCT_EXPORT_METHOD(getToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseR
[_bridge.eventDispatcher sendDeviceEventWithName:@"FCMTokenRefreshed" body:[[FIRInstanceID instanceID] token]];
}
RCT_EXPORT_METHOD(requestPermissions)
RCT_EXPORT_METHOD(requestPermissions:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
if (RCTRunningInAppExtension()) {
return;
@ -265,6 +265,9 @@ RCT_EXPORT_METHOD(requestPermissions)
//iOS 7 or below
[app registerForRemoteNotificationTypes:(NSUInteger)allNotificationTypes];
}
// Unfortunately on iOS 9 or below, there's no way to tell whether the user accepted or
// rejected the permissions popup
resolve(@{@"status":@"unknown"});
} else {
// iOS 10 or later
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
@ -275,11 +278,12 @@ RCT_EXPORT_METHOD(requestPermissions)
[[UNUserNotificationCenter currentNotificationCenter]
requestAuthorizationWithOptions:authOptions
completionHandler:^(BOOL granted, NSError * _Nullable error) {
resolve(@{@"granted":@(granted)});
}
];
#endif
}
[[UIApplication sharedApplication] registerForRemoteNotifications];
}