前一段时间做的项目里面需要用到极光推送,后面客户提出要求还需要在设置里面家推送开关,所以就查了很多资料,下面是一点成果。
一.我暂时还没发现有推送开关的苹果应用,一般的做法是在获取当前推送的状态显示在推送里面,然后提示用户在设置里面开关推送。qq,微信目前都是这么做的。
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[[UIApplication sharedApplication] registerForRemoteNotifications];
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
UIUserNotificationType types = [[UIApplication sharedApplication] currentUserNotificationSettings].types;
if (types == UIUserNotificationTypeNone) {
NSLog(@"没有开启推送");
self.npns = @"已关闭";
}else{
self.npns = @"已开启";
}
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (UIRemoteNotificationTypeNone == types) {
NSLog(@"没有开启推送");
self.npns = @"已关闭";
}else {
self.npns = @"已开启";
}
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
if (section == 0) {
NSString *la = @"请在iPhone的“设置”-“通知”中进行修改。";
return la;
}
return nil;
}