//引入头文件
#import <UserNotifications/UserNotifications.h>
- (void)viewDidAppear:(BOOL)animated {
//首先判断应用通知是否授权,注意iOS10.0之后方法不一样
if (@available(iOS 10.0, *)) {
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.authorizationStatus == UNAuthorizationStatusNotDetermined)
{
NSLog(@"未选择");
[self opentNotificationAlert];
}else if (settings.authorizationStatus == UNAuthorizationStatusDenied){
NSLog(@"未授权");
[self opentNotificationAlert];
}else if (settings.authorizationStatus == UNAuthorizationStatusAuthorized){
NSLog(@"已授权");
}
}];
} else {
if ([[UIApplication sharedApplication] currentUserNotificationSettings].types == 0) {
[self opentNotificationAlert];
}
}
}
/** 跳转系统设置方法*/
- (void)opentNotificationAlert {
/**< 弹出框 */
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"推送通知关闭"
message:@"请前往打开通知,获取更多精彩瞬间!"
preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=NOTIFICATIONS_ID&path=com.xxx.xxx"]];//prefs:root=服务&path=项目bundleID }
}]; [self presentViewController:alertController animated:YES completion:nil]; }
iOS判断系统通知权限及进入设置
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 如果app中有推送功能,那么一般app的设置中都会有一个UISwitch开关来控制是否接收通知,或者用户可以选择关...
- 当APP中有推送的时候就要考虑到通知权限是否用户有没有开启权限的情况,下面就是对判断用户是否开启权限并且跳转到权限...
- 有时候产品要求增加一个推送通知的开关(有些还要求具体到哪些通知,比如广告类? 比如重大热点等?)。 我们首先想到的...