Commit 0f630d5f by Tonghdj

[iOS] update requestPermission

parent 28bb7af0
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array/>
</dict>
</plist>
...@@ -23,30 +23,30 @@ ...@@ -23,30 +23,30 @@
completionHandler(status); completionHandler(status);
return; return;
} }
dispatch_async(dispatch_get_main_queue(), ^{
if(@available(iOS 10.0, *)) { if(@available(iOS 10.0, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
UNAuthorizationOptions authorizationOptions = 0;
UNAuthorizationOptions authorizationOptions = 0; authorizationOptions += UNAuthorizationOptionSound;
authorizationOptions += UNAuthorizationOptionSound; authorizationOptions += UNAuthorizationOptionAlert;
authorizationOptions += UNAuthorizationOptionAlert; authorizationOptions += UNAuthorizationOptionBadge;
authorizationOptions += UNAuthorizationOptionBadge; [center requestAuthorizationWithOptions:(authorizationOptions) completionHandler:^(BOOL granted, NSError * _Nullable error) {
[center requestAuthorizationWithOptions:(authorizationOptions) completionHandler:^(BOOL granted, NSError * _Nullable error) { if (!granted || error != nil) {
if (!granted || error != nil) { completionHandler(PermissionStatusDenied);
completionHandler(PermissionStatusDenied); return;
return; }
} }];
completionHandler(PermissionStatusGranted); } else {
}]; UIUserNotificationType notificationTypes = 0;
} else { notificationTypes |= UIUserNotificationTypeSound;
UIUserNotificationType notificationTypes = 0; notificationTypes |= UIUserNotificationTypeAlert;
notificationTypes |= UIUserNotificationTypeSound; notificationTypes |= UIUserNotificationTypeBadge;
notificationTypes |= UIUserNotificationTypeAlert; UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];
notificationTypes |= UIUserNotificationTypeBadge; [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil]; }
[[UIApplication sharedApplication] registerUserNotificationSettings:settings]; [[UIApplication sharedApplication] registerForRemoteNotifications];
completionHandler(PermissionStatusGranted); completionHandler(PermissionStatusGranted);
} });
} }
+ (PermissionStatus)permissionStatus { + (PermissionStatus)permissionStatus {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment