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

问题描述 投票:1回答:1

我的要求是 - 如果用户关闭了应用程序的通知,用户在此时打开应用程序,它将提示应用程序的开启通知,当点击警报视图应用程序的正常按钮时,将重定向到通知屏幕用户只需点击开关按钮即可开启通知。

在ios8 +中有可能吗?

我想重定向这个屏幕

enter image description here

谢谢

ios notifications settings uialertview uialertcontroller
1个回答
3
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.