iOS8 定位方法

來源:互聯網
上載者:User

標籤:des   blog   http   io   ar   os   使用   sp   for   

 在iOS8之後,在使用之前的定位方法的話,程式接收不到應用調用系統服務的提示,需要做一下更改。
在iOS8中,定位的使用有兩種,一種是在使用該應用的時候訪問使用者的位置資訊,需要在另外一種是允許在並未使用應用程式的時候訪問使用者的位置資訊。
代碼如下:
    self.locationManager = [[CLLocationManager alloc] init];
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        [self.locationManager requestAlwaysAuthorization];
        // 需要在plist檔案中添加預設預設的欄位“NSLocationAlwaysUsageDescription”,這個提示是:“允許應用程式在您並未使用該應用程式時訪問您的位置嗎?”NSLocationAlwaysUsageDescription對應的值是告訴使用者使用定位的目的或者是標記。
        [self.locationManager requestWhenInUseAuthorization];
// 需要在plist檔案中添加預設預設的欄位“NSLocationWhenInUseDescription”,這個時候的提示是:“允許應用程式在您使用該應用程式時訪問您的位置嗎?”
    }
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationManager.distanceFilter = 1000.0f;
    [self.locationManager startUpdatingLocation];
本地通知:在iOS8之後,之前使用的本地通知的方法,使用者不再能收到系統提示了,需要在建立本地通知的時候進行註冊,代碼如下:
// 初始化一個本地通知
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
 // 設定本地通知的時間
    NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
 
/*下面的幾行代碼是需要添加的
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];
    [[UIApplication sharedApplication]         
                registerUserNotificationSettings:settings];
*/
// 註冊通知
    [application scheduleLocalNotification:localNotification];  

iOS8 定位方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.