標籤: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 定位方法