iOS開發之打開系統設置通知權限頁面


- (void)viewDidAppear:(BOOL)animated 
{
  //首先判斷應用通知是否授權,注意iOS10.0之后方法不一樣
if (@available(iOS 10.0, *)) { [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { if (settings.authorizationStatus == UNAuthorizationStatusNotDetermined) { NSLog(@"未選擇"); [self opentNotificationAlert]; }else if (settings.authorizationStatus == UNAuthorizationStatusDenied){ NSLog(@"未授權"); [self opentNotificationAlert]; }else if (settings.authorizationStatus == UNAuthorizationStatusAuthorized){ NSLog(@"已授權"); } }]; } else { if ([[UIApplication sharedApplication] currentUserNotificationSettings].types == 0) { [self opentNotificationAlert]; } } }
/** 跳轉系統設置方法*/
- (void)opentNotificationAlert
{
/**< 彈出框 */ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"推送通知關閉" message:@"請前往打開通知,獲取更多精彩瞬間!" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self.presentedViewController dismissViewControllerAnimated:YES completion:nil]; if (@available(iOS 10.0, *)) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil]; } else { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=NOTIFICATIONS_ID&path=com.xxx.xxx"]];//prefs:root=服務&path=項目bundleID
     }
  }]; 
  [self presentViewController:alertController animated:YES completion:nil];
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM