iOS極光整合


http://docs.jpush.cn/pages/viewpage.action?pageId=2621727







1、在apple開發者平臺創建 “Apple Push Services”,不贅述

2、下載cer證書後,在鑰匙串導出p12證書,輸入密碼

3、在iOS的app管理界面,上傳p12證書,輸入密碼,點擊上傳。驗證成功

4、xcode增加jpush-ios-2.1.0.a、JPUSHService.h

5、修改應用的 Capabilities 開啓Remote notifications

6、AppDelegate.m 增加代碼


static NSString *appKey = @"********************";
static NSString *channel = @"developer-default";
static BOOL isProduction = TRUE;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        //可以添加自定義categories
        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
                                                          UIUserNotificationTypeSound |
                                                          UIUserNotificationTypeAlert)
                                              categories:nil];
    } else {
        //categories 必須爲nil
        [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                          UIRemoteNotificationTypeSound |
                                                          UIRemoteNotificationTypeAlert)
                                              categories:nil];
    }
    
    [JPUSHService setupWithOption:launchOptions appKey:appKey
                          channel:channel apsForProduction:isProduction];
    
    

    //Resign textField if touched outside of UITextField/UITextView.
    [[IQKeyboardManager sharedManager] setShouldResignOnTouchOutside:YES];
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //將所有返回的json中的id映射成item_id
        [JSONModel setGlobalKeyMapper:[[JSONKeyMapper alloc] initWithDictionary:@{@"id":@"item_id"}]];
    });
    return YES;
}






- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    if (userInfo) {
        // 取得 APNs 標準信息內容
        NSDictionary *aps = [userInfo valueForKey:@"aps"];
        NSString *content = [aps valueForKey:@"alert"]; //推送顯示的內容
        //    badge = [[aps valueForKey:@"badge"] integerValue]; //badge數量
        NSString *sound = [aps valueForKey:@"sound"]; //播放的聲音
        
        // 取得自定義字段內容
        NSString *customizeField1 = [userInfo valueForKey:@"key"]; //自定義參數,key是自己定義的
        NSLog(@"content =[%@], badge=[%ld], sound=[%@], customize field =[%@]",content,badge,sound,customizeField1);
        
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                        message:content
                                                       delegate:self
                                              cancelButtonTitle:@"取消"
                                              otherButtonTitles:@"確定", nil];
        [alert show];
        
        // Required
        [JPUSHService handleRemoteNotification:userInfo];
        [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
        [JPUSHService setBadge:0];
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章