iOS8之後對定位和訊息推送API的修改,ios8api

來源:互聯網
上載者:User

iOS8之後對定位和訊息推送API的修改,ios8api
1.定位     定位是定位,地圖是地圖,在iOS中 CLLocation是專門負責定位或者擷取位置資訊的;而MAPkit是專門負責地圖顯示的

    位置管理器(CLLocationManager) :負責擷取,同時負責監控使用者位置發生變化
   
    //[注意] 位置管理器一定要寫成屬性,不是屬性出棧就沒有了
    _manager = [[CLLocationManager alloc] init];
    
    //設定位置管理器代理   <CLLocationManagerDelegate>
    _manager.delegate = self;
    
    //設定最小更新位置
    _manager.distanceFilter = 50.0f;  //單位 是 “米”
    //設定定位精確度,精確度越高 越費電
    _manager.desiredAccuracy = kCLLocationAccuracyBest;

   

   [注:]蘋果在iOS8裡面修改了定位授權協議,也就意味著你原來的app在iOS8上很可能無法定位。目前最好的辦法就是在app啟動的時候調用IOS8的定位授權API來擷取使用者的授權,這樣就不要在其他地方做修改了,如下

 

    [_manager requestAlwaysAuthorization];

    [_manager requestWhenInUseAuthorization];

     [注:]   還需要在plist檔案裡面對 NSLocationAlwaysUsageDescription,NSLocationWhenInUseDescription 倆個屬性進行添加,value可以為空白;

    //讓位置管理器生效,開始更新位置變化

    [_manager startUpdatingLocation];

 

2.訊息推送API的修改

 iOS常用的第三方推送伺服器常用的有極光和信鴿;本次介紹信鴿伺服器

 

從可以看出:

1.首先在你的app中註冊通知, 註冊通知時區別就在iOS8前後,區別如下

 

    //[注]如果你的系統是iOS8或者之後的   

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        
        
        //設定使用者通知的表現形式
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]];
        
        
        //註冊遠程通知  申請 device token
        [[UIApplication sharedApplication] registerForRemoteNotifications];
        
    } else {
        //[注]註冊一個遠程通知,這個遠程通知,有文字,角標,聲音
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
    }

 

    //註冊信鴿服務 只有註冊這個服務後,之後的資料才會發往信鴿伺服器,只有註冊後,信鴿伺服器才可以向這個app 推送訊息
    

+(void)startApp:(uint32_t)appId appKey:(NSString *)appKey;

參數說明:
     Access Id: 通過xg.qq.com註冊app時得到的Access Id。
    Access key:通過xg.qq.com註冊app時得到的Access key。

 

    例如: [XGPush startApp:1234567 appKey:@"IF3W91AV58NC"];

 

2、接收到 APNS 伺服器返回給我們的 device token
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    
    //向信鴿註冊這個裝置標示符
    //註冊之後信鴿的裝置列表中才有你的這個真機
    NSString *token = [XGPush registerDevice:deviceToken];
    NSLog(@"token: %@",token);
    
    
}

 

3、應用程式將device token發送給PUSH服務端程式。

4、服務端程式向APNS服務發送訊息。

5、APNS服務將訊息發送給iPhone應用程式。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.