[ios][messaging] hasPermission now correctly returns true/false instead of 1/0 - fixes #1547

This commit is contained in:
Salakar
2019-01-04 13:10:43 +00:00
parent 1d271736fa
commit d5fd178841
2 changed files with 7 additions and 2 deletions

View File

@@ -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));
}];
}
}

View File

@@ -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);
}
});
});