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

iOS成长之路-关于推送

2015-11-09 10:45 411 查看
 

  前一段时间做的项目里面需要用到极光推送,后面客户提出要求还需要在设置里面家推送开关,所以就查了很多资料,下面是一点成果。

一.我暂时还没发现有推送开关的苹果应用,一般的做法是在获取当前推送的状态显示在推送里面,然后提示用户在设置里面开关推送。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;
}

二.推送声音的设置,推送声音需要与服务器联调,服务器传过来的json里面有sounds字段

   这里参考一下这位大神的文章 http://blog.csdn.net/like7xiaoben/article/details/9001806     
       服务器端传过来什么字段,客户端就播放对应字段名字的声音文件。 
                        
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 推送