iOS通知----极光推送(四)

极光推送流程

1.创建项目, 配置cocoapods; 极光官网不支持Cocoapods, 这里仅是网友自己上传的, 建议跳过该步骤.

$ pod search JPushSDK

2.注册极光账号
3.创建应用, 按照要求填写iOS相关要求, 之前文章中下载的p12证书排上用场了.

iOS通知----极光推送(四)_第1张图片
Paste_Image.png
iOS通知----极光推送(四)_第2张图片
Paste_Image.png
如果之前证书创建不正确, 请参考关于iOS通知----前期配置(一)

查看创建的应用

之后在代码中需要使用该key

iOS通知----极光推送(四)_第3张图片
Paste_Image.png

4.极光SDK概述, 之前已经使用系统推送, 可以大致的浏览一下这个流程;
5.配置依赖库, 下载SDK

第一. 前期配置

1. lib子文件夹(包含JPUSHService.h、jpush-ios-x.x.x.a)添加到你的工程目录中。

2. 必要的框架
CFNetwork.framework
CoreFoundation.framework
CoreTelephony.framework
SystemConfiguration.framework
CoreGraphics.framework
Foundation.framework
UIKit.framework
Security.framework
Xcode7添加libz.tbd;Xcode7以下添加libz.dylib

2.创建plist文件--PushConfig.plist ====(可选)

1. CHANNEL: 指明应用程序包的下载渠道,为方便分渠道统计,具体值由你自行定义,如:App Store。
2. APP_KEY: 创建应用后自动生成的AppKey值。
3. APS_FOR_PRODUCTION: 0 (默认值)表示采用的是开发证书,1 表示采用生产证书发布应用。

第二. 调用极光推送代码

1.注册极光


#import "AppDelegate.h"
#import "JPUSHService.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        //可以添加自定义categories
        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
                                                          UIUserNotificationTypeSound |
                                                          UIUserNotificationTypeAlert)
                                              categories:nil];
    } else {
        //categories 必须为nil
        [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                          UIRemoteNotificationTypeSound |
                                                          UIRemoteNotificationTypeAlert)
                                              categories:nil];
    }
    
   /*!
     * @abstract 启动SDK
     *
     * @param launchingOption 启动参数.
     * @param appKey 一个JPush 应用必须的,唯一的标识. 请参考 JPush 相关说明文档来获取这个标识.
     * @param channel 发布渠道. 可选.
     * @param isProduction 是否生产环境. 如果为开发状态,设置为 NO; 如果为生产状态,应改为 YES.
     * @param advertisingIdentifier 广告标识符(IDFA) 如果不需要使用IDFA,传nil.
     *
     * @discussion 提供SDK启动必须的参数, 来启动 SDK.
     * 此接口必须在 App 启动时调用, 否则 JPush SDK 将无法正常工作.
     */

    [JPUSHService setupWithOption:launchOptions appKey:@"1ff9db3a7370c83a77f66cb0"
                          channel:@"Test"
                 apsForProduction:NO
            advertisingIdentifier:nil];
    
    return YES;

}

2.注册DeviceToken


- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    /// Required - 注册 DeviceToken
    [JPUSHService registerDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    
    // Required,For systems with less than or equal to iOS6
    //处理收到的 APNs 消息
    [JPUSHService handleRemoteNotification:userInfo];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    
    // IOS 7 Support Required
    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    //Optional
    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}

发送推送消息

登陆--极光应用管理

iOS通知----极光推送(四)_第4张图片
Paste_Image.png

*** 恭喜你, 极光远程推送基本使用已经完成. ***

更多精彩内容请关注“IT实战联盟”哦~~~


iOS通知----极光推送(四)_第5张图片
IT实战联盟.jpg

你可能感兴趣的:(iOS通知----极光推送(四))