概述
其实简书上关于极光推送的文章已经很多,并且也很详细,所以,此篇文章仅作为自己日后的一个参考,仅此一点存在价值。so,本文讲述一下配置极光推送的步骤:
1.先说证书的事情:
developer.apple.com---->identifiers--->> 选择APP IDS. 创建一个app id , 填写需要推送的项目的 bundle id,创建完成之后,开启推送服务,创建推送证书,(有两个),创建完推送证书之后,要导出到桌面的 p12, 导出的时候要分清哪个是开发的,哪个是发布的,关于导出时候,不能展开证书的情况我不知道真假,反正不展开就好。然后把两个p12上传到极光推送的官网应用上。
2.这两个地方开启
3.导入必要的依赖库,如图:
4.把极光的文件夹(Lib)拖入工程,最好 add files to...,如下图所示:
// 极光推送的配置信息
static NSString *appKey =@"";//申请应用成功以后官方会提供给你
static NSString *channel =@"";
static BOOL isProduction =FALSE;
在Appdelegate.m中导入头文件#import “JPUSHService.h”
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 极光推送
//Required
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
[JPUSHService registerForRemoteNotificationConfig:entity delegate:nil];
#endif
} else 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];
}
returnYES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
[UIApplicationsharedApplication].applicationIconBadgeNumber =0;
}
#pragma mark - 极光推送的配置方法----------
// 极光推送的配置方法
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"获得了token值为::::%@",deviceToken);
// Required
[JPUSHServiceregisterDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Required,For systems with less than or equal to iOS6
[JPUSHServicehandleRemoteNotification:userInfo];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// IOS 7 Support Required
[JPUSHServicehandleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
//Optional
NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}
最后
以上就是不安秀发为你收集整理的iOS - 关于极光推送的步骤的全部内容,希望文章能够帮你解决iOS - 关于极光推送的步骤所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复