看开 發表於 2019-7-24 16:48:00

iOS开发之打开系统设置通知权限页面

<div class="cnblogs_code">
<pre>- (<span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)">)viewDidAppear:(BOOL)animated <br>{<br>  //首先判断应用通知是否授权,注意iOS10.0之后方法不一样
    </span><span style="color: rgba(0, 0, 255, 1)">if</span> (@available(iOS <span style="color: rgba(128, 0, 128, 1)">10.0</span>, *<span style="color: rgba(0, 0, 0, 1)">)) {
      [ getNotificationSettingsWithCompletionHandler:</span>^(UNNotificationSettings *<span style="color: rgba(0, 0, 0, 1)"> _Nonnull settings) {
            </span><span style="color: rgba(0, 0, 255, 1)">if</span> (settings.authorizationStatus ==<span style="color: rgba(0, 0, 0, 1)"> UNAuthorizationStatusNotDetermined)
            {
                NSLog(</span><span style="color: rgba(128, 0, 0, 1)">@"</span><span style="color: rgba(128, 0, 0, 1)">未选择</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
                ;
            }</span><span style="color: rgba(0, 0, 255, 1)">else</span> <span style="color: rgba(0, 0, 255, 1)">if</span> (settings.authorizationStatus ==<span style="color: rgba(0, 0, 0, 1)"> UNAuthorizationStatusDenied){
                NSLog(</span><span style="color: rgba(128, 0, 0, 1)">@"</span><span style="color: rgba(128, 0, 0, 1)">未授权</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
                ;
            }</span><span style="color: rgba(0, 0, 255, 1)">else</span> <span style="color: rgba(0, 0, 255, 1)">if</span> (settings.authorizationStatus ==<span style="color: rgba(0, 0, 0, 1)"> UNAuthorizationStatusAuthorized){
                NSLog(</span><span style="color: rgba(128, 0, 0, 1)">@"</span><span style="color: rgba(128, 0, 0, 1)">已授权</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
            }
      }];
    } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
      </span><span style="color: rgba(0, 0, 255, 1)">if</span> ([ currentUserNotificationSettings].types == <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">) {
            ;
      }
    }
}
<br>/** 跳转系统设置方法*/
</span>- (<span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)">)opentNotificationAlert <br>{
    </span><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">*&lt; 弹出框 </span><span style="color: rgba(0, 128, 0, 1)">*/</span><span style="color: rgba(0, 0, 0, 1)">
    UIAlertController </span>*alertController = [UIAlertController alertControllerWithTitle:<span style="color: rgba(128, 0, 0, 1)">@"</span><span style="color: rgba(128, 0, 0, 1)">推送通知关闭</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
                                                                           message:</span><span style="color: rgba(128, 0, 0, 1)">@"</span><span style="color: rgba(128, 0, 0, 1)">请前往打开通知,获取更多精彩瞬间!</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:</span><span style="color: rgba(128, 0, 0, 1)">@"</span><span style="color: rgba(128, 0, 0, 1)">取消</span><span style="color: rgba(128, 0, 0, 1)">"</span> style:UIAlertActionStyleDefault handler:^(UIAlertAction *<span style="color: rgba(0, 0, 0, 1)"> _Nonnull action) {

    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:</span><span style="color: rgba(128, 0, 0, 1)">@"</span><span style="color: rgba(128, 0, 0, 1)">确定</span><span style="color: rgba(128, 0, 0, 1)">"</span> style:UIAlertActionStyleDefault handler:^(UIAlertAction *<span style="color: rgba(0, 0, 0, 1)"> _Nonnull action) {
      ;
      </span><span style="color: rgba(0, 0, 255, 1)">if</span> (@available(iOS <span style="color: rgba(128, 0, 128, 1)">10.0</span>, *<span style="color: rgba(0, 0, 0, 1)">)) {
</span><span style="color: rgba(0, 0, 0, 1)">            [ openURL: options:@{} completionHandler:nil];
      } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
            [ openURL:];<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">prefs:root=服务&amp;path=项目</span>bundleID<br>     } </pre>
<pre><span style="color: rgba(0, 0, 0, 1)">  }]; <br>  ; <br>}</span></pre>
</div>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/hecanlin/p/11239144.html
頁: [1]
查看完整版本: iOS开发之打开系统设置通知权限页面