首页 > 系统 > iOS > 正文

IOS 远程通知兼容(IOS7,IOS8)实例详解

2019-10-21 18:47:18
字体:
来源:转载
供稿:网友

IOS 远程通知

1.证书推送安装

 证书的操作过程我就不说了,网上一大堆,首先我要说一下为什么要这些证书其实就是告诉苹果服务器三点:

        1.我们要为哪个应用做推送

        2.哪台电脑上做推送调试

        3.哪台手机设备上做推送调试

我把调试做了高亮,因为总有人问为什么我要在mac上双击安装cer文件和mobileprovision文件,就是因为你要调试,如果你不调试你可以生成后不安装.

2.代码实现

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   // Override point for customization after application launch.   if (IS_iOS_8) {     //获取当前UIUserNotificationType状态     UIUserNotificationType oType = application.currentUserNotificationSettings.types;     if (oType == UIUserNotificationTypeNone) {       NSLog(@"通知被禁止");     }else{       UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;       UIUserNotificationSettings* settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];              [application registerUserNotificationSettings:settings];       [application registerForRemoteNotifications];     }        }else{     UIRemoteNotificationType type = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound;     [application registerForRemoteNotificationTypes:type];   }      return YES; } 
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{   //苹果服务器告诉我们的设备编号   NSLog(@"%@,%@",NSStringFromSelector(_cmd),deviceToken);    }   - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{   //我们公司服务器推送给我们的通知   NSLog(@"%@",userInfo); } 

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!


注:相关教程知识阅读请移步到IOS开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表