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

时间:2023-01-13 20:51:20

My requirement is that - if notification for the app is turned off by user and user opens the app at that time it will give alert for turn on notification for the app and when click on okay button of alert view app will redirect to notification screen where user need to click on switch button only to turn on the notifications.

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

Is it possible in ios8+ ?

在ios8 +中有可能吗?

I want to redirect this screen

我想重定向这个屏幕

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

Thanks

1 个解决方案

#1


7  

This code will redirect you to setting of notifications.

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

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:^{}];
}

It will redirect to following screen

它将重定向到以下屏幕

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

#1


7  

This code will redirect you to setting of notifications.

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

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:^{}];
}

It will redirect to following screen

它将重定向到以下屏幕

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