IOS 远程通知兼容(IOS7,IOS8)实例详解
程序员文章站
2024-02-13 19:38:10
ios 远程通知
1.证书推送安装
证书的操作过程我就不说了,网上一大堆,首先我要说一下为什么要这些证书其实就是告诉苹果服务器三点:
&n...
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 定制多样式二维码