add notification permission status
This commit is contained in:
1 parent
1c3886e10c
commit
b52d3e4281
4 files changed
+158
No files matched your search
@@ -167,6 +167,31 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
|
||||
}
|
||||
}
|
||||
|
||||
- (void)getPushPermissionStatus:(CDVInvokedUrlCommand *)command
|
||||
{
|
||||
if (@available(iOS 10.0, *)) {
|
||||
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings *settings) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self sendSuccessForCommand:command dictionary:[self dictionaryFromNotificationSettings:settings]];
|
||||
});
|
||||
}];
|
||||
} else {
|
||||
UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
|
||||
BOOL enabled = settings.types != UIUserNotificationTypeNone;
|
||||
[self sendSuccessForCommand:command dictionary:@{
|
||||
@"type": @"notification",
|
||||
@"platform": @"iOS",
|
||||
@"enabled": @(enabled),
|
||||
@"granted": @(enabled),
|
||||
@"authorizationStatus": enabled ? @"authorized" : @"denied",
|
||||
@"alertEnabled": @((settings.types & UIUserNotificationTypeAlert) != 0),
|
||||
@"soundEnabled": @((settings.types & UIUserNotificationTypeSound) != 0),
|
||||
@"badgeEnabled": @((settings.types & UIUserNotificationTypeBadge) != 0),
|
||||
@"missing": enabled ? @[] : @[@"notification"]
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)getFirebaseToken:(CDVInvokedUrlCommand *)command
|
||||
{
|
||||
NSError *firebaseError = nil;
|
||||
@@ -337,6 +362,61 @@ static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_k
|
||||
return @"touch";
|
||||
}
|
||||
|
||||
- (NSDictionary *)dictionaryFromNotificationSettings:(UNNotificationSettings *)settings API_AVAILABLE(ios(10.0))
|
||||
{
|
||||
NSString *status = [self authorizationStatusName:settings.authorizationStatus];
|
||||
BOOL enabled = settings.authorizationStatus == UNAuthorizationStatusAuthorized;
|
||||
if (@available(iOS 12.0, *)) {
|
||||
enabled = enabled || settings.authorizationStatus == UNAuthorizationStatusProvisional;
|
||||
}
|
||||
if (@available(iOS 14.0, *)) {
|
||||
enabled = enabled || settings.authorizationStatus == UNAuthorizationStatusEphemeral;
|
||||
}
|
||||
|
||||
BOOL alertEnabled = settings.alertSetting == UNNotificationSettingEnabled;
|
||||
BOOL soundEnabled = settings.soundSetting == UNNotificationSettingEnabled;
|
||||
BOOL badgeEnabled = settings.badgeSetting == UNNotificationSettingEnabled;
|
||||
NSArray *missing = enabled ? @[] : @[@"notification"];
|
||||
|
||||
return @{
|
||||
@"type": @"notification",
|
||||
@"platform": @"iOS",
|
||||
@"enabled": @(enabled),
|
||||
@"granted": @(enabled),
|
||||
@"authorizationStatus": status,
|
||||
@"alertEnabled": @(alertEnabled),
|
||||
@"soundEnabled": @(soundEnabled),
|
||||
@"badgeEnabled": @(badgeEnabled),
|
||||
@"missing": missing
|
||||
};
|
||||
}
|
||||
|
||||
- (NSString *)authorizationStatusName:(UNAuthorizationStatus)status API_AVAILABLE(ios(10.0))
|
||||
{
|
||||
switch (status) {
|
||||
case UNAuthorizationStatusNotDetermined:
|
||||
return @"notDetermined";
|
||||
case UNAuthorizationStatusDenied:
|
||||
return @"denied";
|
||||
case UNAuthorizationStatusAuthorized:
|
||||
return @"authorized";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (@available(iOS 12.0, *)) {
|
||||
if (status == UNAuthorizationStatusProvisional) {
|
||||
return @"provisional";
|
||||
}
|
||||
}
|
||||
if (@available(iOS 14.0, *)) {
|
||||
if (status == UNAuthorizationStatusEphemeral) {
|
||||
return @"ephemeral";
|
||||
}
|
||||
}
|
||||
return @"unknown";
|
||||
}
|
||||
|
||||
- (BOOL)ensureFirebaseConfigured:(NSError **)error
|
||||
{
|
||||
if ([FIRApp defaultApp] != nil) {
|
||||
|
||||
Reference in new issue
Block a user