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

时间:2021-05-02

IOS 远程通知

1.证书推送安装

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

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

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

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

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

2.代码实现

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 - (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; } <br> ? 1 2 3 4 5 6 7 8 9 10 11 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{ //苹果服务器告诉我们的设备编号 NSLog(@"%@,%@",NSStringFromSelector(_cmd),deviceToken); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ //我们公司服务器推送给我们的通知 NSLog(@"%@",userInfo); }

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

原文链接:http://blog.csdn.net/mr_yong/article/details/44997571

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章