您的位置:首页 > 其它

极光推送 JPush 项目简单使用

2015-12-24 13:50 429 查看
打开或者关闭推送

- (void)pushSwitch:(UISwitch *)sender {
if (sender.on) {
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"JPushState"];
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
else {
[[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:@"JPushState"];
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
}
}


  

AppDelegate文件中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"JPushState"] isEqualToString:@"1"]) {
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
[APService setupWithOption:launchOptions];
}

}


  

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[APService registerDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[APService handleRemoteNotification:userInfo];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[APService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: