第一步: 创建工程(这一步很简单, 注:工程名用英文)
WX20180917-171700@2x.png第二步: 创建颁发证书
WX20180917-140822@2x.png将生成文件保存到桌面
WX20180917-141138@2x.png
第三步: 创建开发证书的生产证书(这个在开发者证书账号中创建)
3.1 创建App ID
11989677-3b46c1839340175b.png
WX20180917-152429@2x.png WX20180917-153318@2x.png
3.2 创建发布证书
WX20180917-153009@2x.png WX20180917-153645@2x.png WX20180917-153945@2x副本.png WX20180917-154056@2x.png
3.3 创建生成证书
WX20180917-154256@2x.pngWX20180917-154323@2x.png
3.4 生成了两个证书
WX20180917-155056@2x.png
第四步: 生成p12证书
双击上面生成的文件,在"钥匙串"中打开,
WX20180917-155934@2x.png
第五步: 在激光推送服务中进行配置
WX20180917-155307@2x.png[图片上传中...(WX20180917-160234@2x.png-4f9978-1537171386256-0)]
WX20180917-160234@2x.png
第六步: 用Pod或者直接拖拽将激光推送库文件导入文件中
WX20180917-171833@2x.png加入库文件
添加Framework、CFNetwork.framework、CoreFoundation.framework、CoreTelephony.framework、SystemConfiguration.framework、CoreGraphics.framework、Foundation.framework、UIKit.framework、Security.framework、libz.tbd (Xcode7以下版本是libz.dylib)、AdSupport.framework (获取IDFA需要;如果不使用IDFA,请不要添加)、UserNotifications.framework (Xcode8及以上)、libresolv.tbd (JPush 2.2.0及以上版本需要, Xcode7以下版本是libresolv.dylib)(注意:
如果集成JPush 3.0.1及以上版本, 且同时集成极光其他SDK(如:JMessage 3.0.0及以上版本) 1. Cocoapods导入,建议都更新为线上最新版本,来避免Jcore版本不一致导致的冲突。 2. 手动导入,在工程中只需保留一个最新版本的jcore-ios-x.x.x.a静态库文件。)
WX20180917-173652@2x.png WX20180917-170527@2x.png WX20180917-170602@2x.png WX20180917-170720@2x.png
第七步: 在AppDelegate中配置推送信息
7.1 导入头文件
#import <JPUSHService.h>
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#import <UserNotifications/UserNotifications.h>
#endif
#import <AdSupport/AdSupport.h>
static NSString *appKey = @"427ebbd707ec5a290bb72b30";
//static NSString *channel = @" ";
static BOOL isProduction = FALSE;
WX20180917-170819@2x.png
7.2 AppDelegate中设置文件
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self setup_APNs];
[self setup_JpushdidFinishLaunchingWithOptions:launchOptions];
return YES;
}
//添加初始化APNs代码
- (void)setup_APNs{
//Required
//notice: 3.0.0及以后版本注册可以这样写,也可以继续用之前的注册方式
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
// 可以添加自定义categories
// NSSet<UNNotificationCategory *> *categories for iOS10 or later
// NSSet<UIUserNotificationCategory *> *categories for iOS8 and iOS9
}
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
}
//添加初始化JPush代码
- (void)setup_JpushdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Optional
// 获取IDFA
// 如需使用IDFA功能请添加此代码并在初始化方法的advertisingIdentifier参数中填写对应值
NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
// Required
// init Push
// notice: 2.1.5版本的SDK新增的注册方法,改成可上报IDFA,如果没有使用IDFA直接传nil
// 如需继续使用pushConfig.plist文件声明appKey等配置内容,请依旧使用[JPUSHService setupWithOption:launchOptions]方式初始化。
[JPUSHService setupWithOption:launchOptions appKey:appKey
channel:nil
apsForProduction:isProduction
advertisingIdentifier:advertisingId];
}
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
/// Required - 注册 DeviceToken
[JPUSHService registerDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
//Optional
NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}
#pragma mark- JPUSHRegisterDelegate
// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler API_AVAILABLE(ios(10.0)) API_AVAILABLE(ios(10.0)){
// Required
NSDictionary * userInfo = notification.request.content.userInfo;
if (@available(iOS 10.0, *)) {
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
}
} else {
// Fallback on earlier versions
}
if (@available(iOS 10.0, *)) {
completionHandler(UNNotificationPresentationOptionAlert);
} else {
// Fallback on earlier versions
} // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
}
// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)) API_AVAILABLE(ios(10.0)){
// Required
NSDictionary * userInfo = response.notification.request.content.userInfo;
if (@available(iOS 10.0, *)) {
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
}
} else {
// Fallback on earlier versions
}
completionHandler(); // 系统要求执行这个方法
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// Required, iOS 7 Support
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Required,For systems with less than or equal to iOS6
[JPUSHService handleRemoteNotification:userInfo];
}
网友评论