十一岁的加重songxing10000…… ------ 回到博主首页

极光推送 JPush 项目简单使用

打开或者关闭推送

- (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);
}

  

posted @ 2015-12-24 13:50  songxing10000  阅读(211)  评论(0编辑  收藏  举报