ios - 直接从支持 iOS8+ 的 iOS 应用程序重定向到通知设置

标签 ios notifications settings uialertview uialertcontroller

我的要求是 - 如果用户关闭应用程序的通知并且用户当时打开应用程序,它将发出打开应用程序通知的警报,并且当单击警报 View 应用程序的“确定”按钮时将重定向到通知屏幕,用户只需单击开关按钮即可打开通知。

ios8+ 可以吗?

我想重定向此屏幕

enter image description here

谢谢

最佳答案

此代码会将您重定向到通知设置。

if ([[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone)
{
    NSLog(@" Push Notification ON");
}
else
{
    UIAlertController *alertController = [UIAlertController  alertControllerWithTitle:@"Push Notification Service Disable ,please enable it."  message:nil  preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:@"Okay!" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
    {
           @try
           {
                NSLog(@"tapped ok");
                BOOL canOpenSettings = (UIApplicationOpenSettingsURLString != NULL);
                if (canOpenSettings)
                {
                     NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
                     [[UIApplication sharedApplication] openURL:url];
                }
           }
           @catch (NSException *exception)
          {

          }
    }]];
   [self.view presentViewController:alertController animated:YES completion:^{}];
}

它将重定向到以下屏幕

enter image description here

关于ios - 直接从支持 iOS8+ 的 iOS 应用程序重定向到通知设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33413745/

相关文章:

ios - 返回 Int 的可选链接

ios - 难以操作 XIB 文件中的对象。

ios决定是否在客户端代码的某些条件下静音我的远程通知,而不是设置内容可用

Facebook 通知 RSS 提要

c# - 遍历设置文件

c++ - MFC:如何创建带有列表框和多页的选项对话框?

ios - Swift:使用 CGRect 设置 UIButton 图像

ios - 如何在 swift 中读取预加载的 sqlite 数据库

java - 来自 JSON 的通知服务

settings - codenameone 无法打开设计器或设置