标签:
打开或者关闭推送
- (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); }
标签:
原文地址:http://www.cnblogs.com/songxing10000/p/5072821.html