// 检查手机是否开启推送权限功能
-(void) checkCurrentNotificationStatus
{
if (@available(iOS 10 , *)) // 手机系统是ios10.0及以上系统版本
{
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.authorizationStatus == UNAuthorizationStatusDenied)
{
// 没权限 }
}];
}
else if (@available(iOS 8 , *)) // 手机系统是ios8.0及以上系统版本
{
UIUserNotificationSettings * setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (setting.types == UIUserNotificationTypeNone) {
// 没权限 }
}
else {
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (type == UIUserNotificationTypeNone)
{
// 没权限 }
}
}
#pragma mark 没权限的弹窗
-(void) showAlrtToSetting
{
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"您还没有允许****权限" message:@"去设置一下吧" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction * setAction = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
dispatch_async(dispatch_get_main_queue(), ^{
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
});
}];
[alert addAction:cancelAction];
[alert addAction:setAction];
[self presentViewController:alert animated:YES completion:nil];
}
网友评论