Redirect to notification setting directly from iOS app that having support of iOS8+

99封情书 提交于 2019-12-24 12:38:06

问题


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+ ?

I want to redirect this screen

Thanks


回答1:


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



来源:https://stackoverflow.com/questions/33413745/redirect-to-notification-setting-directly-from-ios-app-that-having-support-of-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!