mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-18 08:20:47 +08:00
[ios][messaging] hasPermission now correctly returns true/false instead of 1/0 - fixes #1547
This commit is contained in:
@@ -195,12 +195,14 @@ RCT_EXPORT_METHOD(registerForRemoteNotifications:(RCTPromiseResolveBlock)resolve
|
||||
RCT_EXPORT_METHOD(hasPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
resolve(@([RCTSharedApplication() currentUserNotificationSettings].types != UIUserNotificationTypeNone));
|
||||
BOOL hasPermission = [RCTConvert BOOL:@([RCTSharedApplication() currentUserNotificationSettings].types != UIUserNotificationTypeNone)];
|
||||
resolve(@(hasPermission));
|
||||
});
|
||||
} else {
|
||||
if (@available(iOS 10.0, *)) {
|
||||
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
|
||||
resolve(@(settings.alertSetting == UNNotificationSettingEnabled));
|
||||
BOOL hasPermission = [RCTConvert BOOL:@(settings.alertSetting == UNNotificationSettingEnabled)];
|
||||
resolve(@(hasPermission));
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,11 @@ describe('messaging()', () => {
|
||||
describe('hasPermission()', () => {
|
||||
it('returns fcm token', async () => {
|
||||
const bool = await firebase.messaging().hasPermission();
|
||||
bool.should.be.Boolean();
|
||||
if (device.getPlatform() === 'android') {
|
||||
should.equal(bool, true);
|
||||
} else {
|
||||
should.equal(bool, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user