zoukankan      html  css  js  c++  java
  • 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];
    }
  • 相关阅读:
    【代码笔记】Web-CSS-CSS Display
    【代码笔记】Web-CSS-CSS 分组和嵌套
    【代码笔记】Web-CSS-CSS Padding(填充)
    【代码笔记】Web-CSS-CSS Margin(外边距)
    【代码笔记】Web-CSS-CSS Border(边框)
    【代码笔记】Web-CSS-CSS盒子模型
    【代码笔记】Web-CSS-CSS Table(表格)
    【代码笔记】Web-CSS-CSS样式列表(url)
    【代码笔记】Web-CSS-CSS 链接(link)
    【代码笔记】Web-CSS-CSS Fonts(字体)
  • 原文地址:https://www.cnblogs.com/hecanlin/p/11239144.html
Copyright © 2011-2022 走看看