码迷,mamicode.com
首页 > 移动开发 > 详细

iOS--极光推送

时间:2015-09-25 13:25:05      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

1.SDK集成

    具体需要的库的证书导入极光网这些,可以参考文档。

2.实现推送

    需要注意的地方是带程序在前台的时候,收到的推送不会显示,但是是可以收到数据,这里就需要我们打印

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    // 极光推送
    float systemVersion = [[UIDevice currentDevice].systemVersion floatValue];
    if (systemVersion >= 8.0) {
        //可以添加自定义categories
        [APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
                                                       UIUserNotificationTypeSound |
                                                       UIUserNotificationTypeAlert)
                                           categories:nil];
    } else {
        //categories 必须为nil
        [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                       UIRemoteNotificationTypeSound |
                                                       UIRemoteNotificationTypeAlert)
                                           categories:nil];
    }
    
    // Required
    [APService setupWithOption:launchOptions];
}

#pragma mark - 注册设备推送
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    [APService registerDeviceToken:deviceToken];
}

#pragma mark 推送消息接收
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
   
    // Required
    [APService handleRemoteNotification:userInfo];
    NSLog(@"AppDelegate:%@",userInfo);
   
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    
    
    // IOS 7 Support Required
    [APService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
    NSLog(@"AppDelegate:%@",userInfo);
   
}


iOS--极光推送

标签:

原文地址:http://my.oschina.net/u/2346786/blog/511059

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