#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 -应用外接收推送信息JPush
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {
NSDictionary*aps = [userInfovalueForKey:@"aps"];//取得APNs标准信息内容
NSString*alert = [apsvalueForKey:@"alert"];//推送显示的内容key为alert
NSIntegerbadge = [[apsvalueForKey:@"badge"]integerValue];//badge数量
//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应用内接收自定义消息
- (void)addJPushCustomMessage {
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(networkDidReceiveMessage:)name:kJPFNetworkDidReceiveMessageNotificationobject:nil];
}
- (void)networkDidReceiveMessage:(NSNotification*)notification {
NSDictionary*userInfo = [notificationuserInfo];
NSString*content = [userInfovalueForKey:@"content"];//推送显示的内容key为content
UIAlertController*alertController = [UIAlertControlleralertControllerWithTitle:@"通知"message:contentpreferredStyle:UIAlertControllerStyleAlert];
UIAlertAction*okAlertAction = [UIAlertActionactionWithTitle:@"知道了"style:UIAlertActionStyleDefaulthandler:nil];
[alertControlleraddAction:okAlertAction];
[self.window.rootViewControllerpresentViewController:alertControlleranimated:YEScompletion:nil];
}
网友评论