#pragma mark -極光推送
#define kNotificationTypes (UIUserNotificationTypeBadge | UIUserNotificationTypeSound |UIUserNotificationTypeAlert)
- (void)initJPushWithOptions:(NSDictionary*)launchOptions {
if([[UIDevicecurrentDevice].systemVersionfloatValue] >=8.0) {
[JPUSHServiceregisterForRemoteNotificationTypes:kNotificationTypes
categories:nil];//可以添加自定義categories
}else{
[JPUSHServiceregisterForRemoteNotificationTypes:kNotificationTypes
categories:nil];//categories必須為nil
}
//啟動SDK
[JPUSHServicesetupWithOption:launchOptionsappKey:kJPushAppKey
channel:@"App Store"
apsForProduction:NO
advertisingIdentifier:nil];
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
[JPUSHServiceregisterDeviceToken:deviceToken];//注冊DeviceToken
}
#pragma mark -應(yīng)用外接收推送信息JPush
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {
NSDictionary*aps = [userInfovalueForKey:@"aps"];//取得APNs標(biāo)準(zhǔn)信息內(nèi)容
NSString*alert = [apsvalueForKey:@"alert"];//推送顯示的內(nèi)容key為alert
NSIntegerbadge = [[apsvalueForKey:@"badge"]integerValue];//badge數(shù)量
//NSString *sound = [aps valueForKey:@"sound"]; //播放的聲音
UIAlertController*alertController = [UIAlertControlleralertControllerWithTitle:@"通知"message:alertpreferredStyle:UIAlertControllerStyleAlert];
UIAlertAction*okAlertAction = [UIAlertActionactionWithTitle:@"知道了"style:UIAlertActionStyleDefaulthandler:nil];
[alertControlleraddAction:okAlertAction];
[self.window.rootViewControllerpresentViewController:alertControlleranimated:YEScompletion:nil];
[UIApplicationsharedApplication].applicationIconBadgeNumber= badge;
// Required
[JPUSHServicehandleRemoteNotification:userInfo];
}
#pragma mark -添加JPush應(yīng)用內(nèi)接收自定義消息
- (void)addJPushCustomMessage {
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(networkDidReceiveMessage:)name:kJPFNetworkDidReceiveMessageNotificationobject:nil];
}
- (void)networkDidReceiveMessage:(NSNotification*)notification {
NSDictionary*userInfo = [notificationuserInfo];
NSString*content = [userInfovalueForKey:@"content"];//推送顯示的內(nèi)容key為content
UIAlertController*alertController = [UIAlertControlleralertControllerWithTitle:@"通知"message:contentpreferredStyle:UIAlertControllerStyleAlert];
UIAlertAction*okAlertAction = [UIAlertActionactionWithTitle:@"知道了"style:UIAlertActionStyleDefaulthandler:nil];
[alertControlleraddAction:okAlertAction];
[self.window.rootViewControllerpresentViewController:alertControlleranimated:YEScompletion:nil];
}