IOS 远程通知兼容(IOS7,IOS8)实例详解
2019/7/9 22:57:32
本文主要是介绍IOS 远程通知兼容(IOS7,IOS8)实例详解,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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 远程通知兼容(IOS7,IOS8)实例详解的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-12Axios库资料:新手入门必读教程
- 2024-11-11Axios库项目实战:新手入门教程
- 2024-09-29Axios库教程:初学者必备指南
- 2024-08-29Axios库资料:新手入门指南与基本使用教程
- 2024-03-14system bios shadowed
- 2024-03-14gabios
- 2024-02-07iOS应用提交上架的最新流程
- 2024-02-06打包 iOS 的 IPA 文件
- 2023-12-07uniapp打包iOS应用并通过审核:代码混淆的终极解决方案 ?
- 2023-11-25uniapp IOS从打包到上架流程(详细简单) 原创