iOS 极光推送

使用极光推送须要去AppleDevelope中下载证书
这里写图片描写叙述

当中极光推送须要的证书是.p12证书,齿轮状的证书数手机证书

下载完证书须要配置项目project
首先须要导入从官方下载的SDK中的lib目录中的文件
这里写图片描写叙述
然后再去载入须要的框架
这里写图片描写叙述
还须要加入一个.plist文件
这里写图片描写叙述
当中APP_KEY是极光推送的key

上面设置完。又在极光站点注冊完那就须要在AppleDelegate.h代理文件里填写内容了

#import "AppDelegate.h"
#import "JPUSHService.h"
#import "RootController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    RootController *root = [[RootController alloc]init];
    self.window.rootViewController = root;
    [self.window makeKeyAndVisible];

    // Required
    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];
    }

    // Required
    //如需兼容旧版本号的方式。请依然使用[JPUSHService setupWithOption:launchOptions]方式初始化和同一时候使用pushConfig.plist文件声明appKey等配置内容。
    // [JPUSHService setupWithOption:launchOptions];
    [JPUSHService setupWithOption:launchOptions appKey:appKey channel:channel apsForProduction:isProduction];
    return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    // Required
    [JPUSHService registerDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    // Required,For systems with less than or equal to iOS6
    [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);
}

@end

还须要结合极光官方文档———— 最重要的还是证书

posted on 2017-06-24 19:31  yjbjingcha  阅读(214)  评论(0编辑  收藏  举报

导航