iOS 极光推送

1.注册极光推送开发者账号

https://www.jpush.cn

2.登陆极光网站--创建应用

3.上传推送的开发证书和产品证书

  注:上传p12证书,所以上传前要把cer证书转成p12证书,也就是交换证书

  创建好应用后,记录下APP_KEY

4.在项目中集成极光推送

  下载极光推送SDK

  https://www.jpush.cn/common/products#product-sdk

    

  注:服务器端开发需要下载对应的SDK

5.必要的框架

  • CFNetwork.framework
  • CoreFoundation.framework
  • CoreTelephony.framework
  • SystemConfiguration.framework
  • CoreGraphics.framework
  • Foundation.framework
  • UIKit.framework
  • Security.framework
  • libz.dylib

6.创建并配置PushConfig.plist文件

  • CHANNEL:Publish channel 代表发布版本
  • APP_KEY:填步骤3.1获得的APP_KEY. 极光官网的应用管理中心也是可以查到的
  • APS_FOR_PRODUCTION:
    • 1.3.1版本新增,表示应用是否采用生产证书发布( Ad_Hoc 或 APP Store ),0 (默认值)表示采用的是开发者证书,1 表示采用生产证书发布应用。
    • 此处设置的值建议按对应证书来设置值。
    • 在1.2.2或之前版本的配置文件中,有 TEST_MODE 这个键,新版的SDK不再使用,可以将它删除。

 

7.添加代码到项目

 1     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 2 {
 3     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
 4     self.window.backgroundColor = [UIColor whiteColor];
 5     [self.window makeKeyAndVisible];
 6 
 7     // Required
 8 #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
 9    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
10     //可以添加自定义categories
11     [APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
12                                                    UIUserNotificationTypeSound |
13                                                    UIUserNotificationTypeAlert)
14                                        categories:nil];
15   } else {
16     //categories 必须为nil
17     [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
18                                                    UIRemoteNotificationTypeSound |
19                                                    UIRemoteNotificationTypeAlert)
20                                        categories:nil];
21   }
22 #else
23     //categories 必须为nil
24   [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
25                                                  UIRemoteNotificationTypeSound |
26                                                  UIRemoteNotificationTypeAlert)
27                                      categories:nil];
28 #endif
29     // Required
30     [APService setupWithOption:launchOptions];
31 
32     return YES;
33 }
34 
35 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
36 
37     // Required
38     [APService registerDeviceToken:deviceToken];
39 }
40 
41 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
42 
43     // Required
44     [APService handleRemoteNotification:userInfo];
45 }
46 
47 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
48 
49 
50   // IOS 7 Support Required
51   [APService handleRemoteNotification:userInfo];
52   completionHandler(UIBackgroundFetchResultNewData);
53 }

8.在极光官网--发送通知

  8.1设置推送消息

  8.2设置推送对象,一般勾选全部

9.极光还有统计功能

posted @ 2015-01-19 01:49  oumygade  阅读(421)  评论(0编辑  收藏  举报