码迷,mamicode.com
首页 > 其他好文 > 详细

极光推送 JPush 项目简单使用

时间:2015-12-24 14:55:14      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

打开或者关闭推送

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

  

极光推送 JPush 项目简单使用

标签:

原文地址:http://www.cnblogs.com/songxing10000/p/5072821.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!