Add a promise response to iOS messaging requestPermissions to return permission popup response (iOS 10+)
This commit is contained in:
parent
187f7cd7b9
commit
43df6b5564
|
@ -247,7 +247,7 @@ RCT_EXPORT_METHOD(getToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseR
|
||||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"FCMTokenRefreshed" body:[[FIRInstanceID instanceID] token]];
|
[_bridge.eventDispatcher sendDeviceEventWithName:@"FCMTokenRefreshed" body:[[FIRInstanceID instanceID] token]];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(requestPermissions)
|
RCT_EXPORT_METHOD(requestPermissions:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
||||||
{
|
{
|
||||||
if (RCTRunningInAppExtension()) {
|
if (RCTRunningInAppExtension()) {
|
||||||
return;
|
return;
|
||||||
|
@ -265,6 +265,9 @@ RCT_EXPORT_METHOD(requestPermissions)
|
||||||
//iOS 7 or below
|
//iOS 7 or below
|
||||||
[app registerForRemoteNotificationTypes:(NSUInteger)allNotificationTypes];
|
[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 {
|
} else {
|
||||||
// iOS 10 or later
|
// iOS 10 or later
|
||||||
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
|
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
|
||||||
|
@ -275,11 +278,12 @@ RCT_EXPORT_METHOD(requestPermissions)
|
||||||
[[UNUserNotificationCenter currentNotificationCenter]
|
[[UNUserNotificationCenter currentNotificationCenter]
|
||||||
requestAuthorizationWithOptions:authOptions
|
requestAuthorizationWithOptions:authOptions
|
||||||
completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
||||||
|
resolve(@{@"granted":@(granted)});
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue