修改 AppDelegate.m, 添加
#import "APService.h"
#import "JPushPlugin.h" //viper
didFinishLaunchingWithOptions函数中添加
// Required
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//可以添加自定义categories
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories 必须为nil
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
#else
//categories 必须为nil
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
#endif
// Required
[APService setupWithOption:launchOptions];
didRegisterForRemoteNotificationsWithDeviceToken中添加
// Required
[APService registerDeviceToken:deviceToken];
[APService setDebugMode];
添加函数
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Required
[APService handleRemoteNotification:userInfo];
BOOL isActive;
if (application.applicationState == UIApplicationStateActive) {
isActive = TRUE;
} else {
isActive = FALSE;
}
NSDictionary *dict=[[NSMutableDictionary alloc] initWithDictionary:userInfo];
[dict setValue: [[NSNumber alloc] initWithBool:isActive] forKey:@"isActive" ];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPlugReceiveNotificaiton
object:dict] ;//viper
}