标签:
导出证书时要选中证书文件,不要展开private key
全局配置
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict
开启Remote notifications,需要在Xcode 中修改应用的 Capabilities 开启Remote notifications
在Appdelegate.m中导入头文件#import “JPUSHService.h”
在didFinishLaunchingWithOptions方法中写入以下代码,有的地方要按你自己的信息填
1 // Required 2 if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { 3 //可以添加自定义categories 4 [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert)categories:nil]; 5 } else { 6 //categories 必须为nil 7 [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)categories:nil]; 8 } 9 10 [JPUSHService setupWithOption:launchOptions appKey:你的appKey(字符串),在极光的应用详情中可以看到" channel:@""(这个不填就行) apsForProduction:这个值生产环境为YES,开发环境为NO(BOOL值)]; 11 12 13 14 创建 15 16 -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 17 18 19 方法中注册设备(去掉这个) 20 21 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 22 //这个方法是设置别名和tag 可省 23 // [JPUSHService setTags:nil alias:@"WzxJiang" fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) { 24 // NSLog(@"rescode: %d, \ntags: %@, \nalias: %@\n", iResCode, iTags , iAlias); 25 // }]; 26 // Required 27 [JPUSHService registerDeviceToken:deviceToken]; 28 } 29 30 31 32 创建 33 34 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler: 35 36 37 App在后台时收到推送时的处理 38 39 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { 40 //iOS 7及之后才能用,现在没人适配iOS6了吧... 41 // IOS 7 Support Required 42 [JPUSHService handleRemoteNotification:userInfo]; 43 completionHandler(UIBackgroundFetchResultNewData); 44 } 45 46 47 48 在applicationWillEnterForeground方法(App即将进入前台)中将小红点清除 49 50 - (void)applicationWillEnterForeground:(UIApplication *)application { 51 NSLog(@"进入前台"); 52 [UIApplication sharedApplication].applicationIconBadgeNumber = 0; 53 } 54 56 57 创建 58 59 didFailToRegisterForRemoteNotificationsWithError 60 61 62 方法,处理接收推送错误的情况(一般不会…) 63 - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { 64 //Optional 65 NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error); 66 }
标签:
原文地址:http://www.cnblogs.com/somethingWithiOS/p/5941295.html