您的位置:首页 > 移动开发

兼容iOS7以上设置推送,跳转app设置界面

2016-03-10 16:26 429 查看
1、首先我们要明确推送实际上有2个开关:

(1)iOS系统(APNS协作)

(2)本地(我们自己的)服务器

所以,为了更好的用户体验,并且iOS有限制的情况下:

从关闭到打开,只能跳转APP 在系统设置 里的页面。

从打开到关闭,将是否接收推送的设置传给服务器端,服务器根据设置选择是否发送推送。假如某用户关闭推送,服务就不给改用户发送推送了。

2、另外一个要解决的是跳转iOS7 的app 设置界面的功能,附上代码:

//跳转到当前app的设置推送界面, iOS7的有点问题(未验证能否通过appstore审核)

+ (void)JumpToPushSetting

{

if ([self getOSVersion] >= 8.0f) {

NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

if([[UIApplication sharedApplication] canOpenURL:url]) {

NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];

[[UIApplication sharedApplication] openURL:url];

}

}

else {

NSString *destPath = [NSString stringWithFormat:@"prefs:root=NOTIFICATIONS_ID&path=%@", [self getBundleID]];

NSURL*url2=[NSURL URLWithString:destPath];

[[UIApplication sharedApplication] openURL:url2];

}

}

//是否允许推送

+ (BOOL)IsAllowedNotification {

//iOS8 check if user allow notification

if ([self getOSVersion] >= 8.0f) {// system is iOS8

UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];

if (UIUserNotificationTypeNone != setting.types) {

return YES;

}

else

return NO;

} else {//iOS7

UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

if(UIRemoteNotificationTypeNone != type)

return YES;

else

return NO;

}

return NO;

}

//注册推送消息显示方式

+ (void)RegistPushNotificationSettings

{

UIApplication *application = [UIApplication sharedApplication];

//这下面注册,在第一次打开app的时候,会显示给用户
“是否允许推送通知”窗口

if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])

{

//IOS8

//创建UIUserNotificationSettings,并设置消息的显示类类型

UIUserNotificationSettings *notiSettings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIRemoteNotificationTypeSound) categories:nil];

[application registerUserNotificationSettings:notiSettings];

} else{ // ios7

[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)];

}

}

+(NSString*)getAppVersion

{

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];

//NSString *name = [infoDictionary objectForKey:@"CFBundleDisplayName"];

NSString *version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];

//NSString *build = [infoDictionary objectForKey:@"CFBundleVersion"];

return version;

}

//获取APP本地的bundle ID

+(NSString*)getBundleID

{

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];

NSString* bundleID = [infoDictionary objectForKey:@"CFBundleIdentifier"];

return bundleID;

}

3、以下是流程图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: