2、启动极光推送功能
static NSString *JPushAppKey = @"6abc87b33b23d35b9c3b86e0";
static NSString *JPushChannel = @"Publish channel";
// static BOOL JPushIsProduction = NO;
#ifdef DEBUG
// 开发 极光FALSE为开发环境
static BOOL const JPushIsProduction = FALSE;
#else
// 生产 极光TRUE为生产环境
static BOOL const JPushIsProduction = TRUE;
#endif
[objc] view plain copy 在CODE上查看代码片派生到我的代码片
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 启动极光推送
// Required
// - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { }
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) // iOS10
{
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
JPUSHRegisterEntity *entity = [[JPUSHRegisterEntity alloc] init];
entity.types = (UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound);
[JPUSHService registerForRemoteNotificationConfig:entity delegate:target];
#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];
}
// Required
// [JPUSHService setupWithOption:launchOptions]
// pushConfig.plist appKey
// 有广告符标识IDFA(尽量不用,避免上架审核被拒)
/*
NSString *JPushAdvertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
[JPUSHService setupWithOption:JPushOptions
appKey:JPushAppKey
channel:JPushChannel
apsForProduction:JPushIsProduction
advertisingIdentifier:JPushAdvertisingId];
*/
// 或无广告符标识IDFA(尽量不用,避免上架审核被拒)
[JPUSHService setupWithOption:options
appKey:JPushAppKey
channel:JPushChannel
apsForProduction:JPushIsProduction];
// 2.1.9版本新增获取registration id block接口。
[JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
if(resCode == 0)
{
// iOS10获取registrationID放到这里了, 可以存到缓存里, 用来标识用户单独发送推送
NSLog(@"registrationID获取成功:%@",registrationID);
[[NSUserDefaults standardUserDefaults] setObject:registrationID forKey:@"registrationID"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
NSLog(@"registrationID获取失败,code:%d",resCode);
}
}];
return YES;
}
3、注册
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[JPUSHService registerDeviceToken:data];
}










