mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-19 13:08:21 +08:00
fix(messaging): registerRemoteNotifictions
This commit is contained in:
@@ -170,10 +170,33 @@ RCT_EXPORT_METHOD(requestPermission:
|
||||
if ([UIApplication sharedApplication].isRegisteredForRemoteNotifications == YES) {
|
||||
customResolver(nil);
|
||||
} else {
|
||||
[[RNFBMessagingAppDelegateInterceptor sharedInstance] setPromiseResolve:customResolver andPromiseReject:reject];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
||||
});
|
||||
|
||||
if (@available(iOS 10.0, *)) {
|
||||
UNAuthorizationOptions authOptions;
|
||||
if (@available(iOS 12.0, *)) {
|
||||
authOptions = UNAuthorizationOptionProvisional | UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
|
||||
} else {
|
||||
authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
|
||||
}
|
||||
|
||||
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError *_Nullable error) {
|
||||
if (error) {
|
||||
[RNFBSharedUtils rejectPromiseWithNSError:reject error:error];
|
||||
} else {
|
||||
[[RNFBMessagingAppDelegateInterceptor sharedInstance] setPromiseResolve:customResolver andPromiseReject:reject];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
||||
});
|
||||
}
|
||||
}];
|
||||
|
||||
} else {
|
||||
// TODO community iOS 9 support could be added here
|
||||
[RNFBSharedUtils rejectPromiseWithUserInfo:reject userInfo:[@{
|
||||
@"code": @"unsupported-platform-version",
|
||||
@"message": @"requestPermission call failed; minimum supported version requirement not met (iOS 10)."} mutableCopy]];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +206,34 @@ RCT_EXPORT_METHOD(registerForRemoteNotifications:
|
||||
) {
|
||||
[[RNFBMessagingAppDelegateInterceptor sharedInstance] setPromiseResolve:resolve andPromiseReject:reject];
|
||||
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
||||
|
||||
if ([UIApplication sharedApplication].isRegisteredForRemoteNotifications == YES) {
|
||||
return resolve(@([RCTConvert BOOL:@(YES)]));
|
||||
}
|
||||
if (@available(iOS 10.0, *)) {
|
||||
UNAuthorizationOptions authOptions;
|
||||
if (@available(iOS 12.0, *)) {
|
||||
authOptions = UNAuthorizationOptionProvisional | UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
|
||||
} else {
|
||||
authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
|
||||
}
|
||||
|
||||
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError *_Nullable error) {
|
||||
if (error) {
|
||||
[RNFBSharedUtils rejectPromiseWithNSError:reject error:error];
|
||||
} else {
|
||||
[[RNFBMessagingAppDelegateInterceptor sharedInstance] setPromiseResolve:resolve andPromiseReject:reject];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
||||
});
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
// TODO community iOS 9 support could be added here
|
||||
[RNFBSharedUtils rejectPromiseWithUserInfo:reject userInfo:[@{
|
||||
@"code": @"unsupported-platform-version",
|
||||
@"message": @"requestPermission call failed; minimum supported version requirement not met (iOS 10)."} mutableCopy]];
|
||||
}
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(unregisterForRemoteNotifications:
|
||||
|
||||
Reference in New Issue
Block a user