判断用户是否打开了推送
#pragma mark - 是否开启APP推送
/**是否开启推送*/
+ (BOOL)isSwitchAppNotification {
if (IOS_VERSION >= 10.0) {
__block BOOL result = NO;
//异步线程中操作是否完成
__block BOOL inThreadOperationComplete = NO;
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.authorizationStatus == UNAuthorizationStatusDenied) {
result = NO;
}else if (settings.authorizationStatus == UNAuthorizationStatusNotDetermined) {
result = NO;
}else if (settings.authorizationStatus == UNAuthorizationStatusAuthorized) {
result = YES;
}else {
result = NO;
}
inThreadOperationComplete = YES;
}];
while (!inThreadOperationComplete) {
[NSThread sleepForTimeInterval:0];
}
return result;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
else if (IOS_VERSION >= 8.0)
{
UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (UIUserNotificationTypeNone != setting.types) {
return YES;
}else {
return NO;
}
}else
{
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if(UIRemoteNotificationTypeNone != type) {
return YES;
}else {
return NO;
}
}
#pragma clang diagnostic pop
}
然后如果用户没有打开推送按钮
跳转到应用相关设置页面
if (switch.on) {
if (IOS_VERSION >= 10.0) {
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication]openURL:url options:@{} completionHandler:^(BOOL success) {
}];
}else{
//[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]] 应用标识
NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"prefs:root=%@",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]]];
[[UIApplication sharedApplication]openURL:url];
}
}
网友评论