part 1 Appkey
part 2 證書及環(huán)境
part 3 代碼部分
在項目didFinishLaunchingWithOptions
調(diào)用[self configurationJiguangWithOption:launchOptions];
即可
#pragma mark 極光推送<可直接拷貝到項目>
static NSString *JiguangAppKey = @"你在極光注冊的key";
static NSString *channel = @"Publish channel";
-(void)configurationJiguangWithOption:(NSDictionary *)launchingOption{
//極光
//Required
//notice: 3.0.0及以后版本注冊可以這樣寫,也可以繼續(xù)用之前的注冊方式
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];
// Optional
// 獲取IDFA
// 如需使用IDFA功能請?zhí)砑哟舜a并在初始化方法的advertisingIdentifier參數(shù)中填寫對應(yīng)值
NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
// Required
// init Push
// notice: 2.1.5版本的SDK新增的注冊方法,改成可上報IDFA俭尖,如果沒有使用IDFA直接傳nil
// 如需繼續(xù)使用pushConfig.plist文件聲明appKey等配置內(nèi)容,請依舊使用[JPUSHService setupWithOption:launchOptions]方式初始化鲫剿。
[JPUSHService setupWithOption:launchingOption appKey:JiguangAppKey
channel:channel
apsForProduction:NO
advertisingIdentifier:advertisingId];
}
//注冊APNs成功并上報DeviceToken
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"My token is: %@", deviceToken);
/// Required - 注冊 DeviceToken
[JPUSHService registerDeviceToken:deviceToken];
}
//實現(xiàn)注冊APNs失敗接口
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
//Optional
NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}
//添加處理APNs通知回調(diào)方法
// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
// Required
NSDictionary * userInfo = notification.request.content.userInfo;
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler(UNNotificationPresentationOptionAlert); // 需要執(zhí)行這個方法仓犬,選擇是否提醒用戶斟赚,有Badge废菱、Sound、Alert三種類型可以選擇設(shè)置
}
// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
// Required
NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler(); // 系統(tǒng)要求執(zhí)行這個方法
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// Required, iOS 7 Support
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
part 4 測試結(jié)果
part 5 推送一個試試效果?
只是簡單版本,后面有時間再增加自定義的