问题
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