花了幾天試圖解決這個問題,但無法找到任何有效的解決方案。我已經檢查了所有在stackoverflow的帖子,並嘗試了所有的解決方案,似乎沒有任何工作。我也嘗試了CLLocation的蘋果測試項目,對我來說工作正常。我以前的點點滴滴,從蘋果的測試項目CLLocation didupdatetolocation不叫
https://developer.apple.com/library/ios/samplecode/LocateMe/Listings/README_md.html
但我的代碼是不工作的。 DidupdateToLocation永遠不會被調用。
這裏是我的代碼(在viewDidLoad中)
_locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
// This is the most important property to set for the manager. It ultimately determines how the manager will
// attempt to acquire location and thus, the amount of power that will be consumed.
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// Once configured, the location manager must be "started"
//
// for iOS 8, specific user level permission is required,
// "when-in-use" authorization grants access to the user's location
//
// important: be sure to include NSLocationWhenInUseUsageDescription along with its
// explanation string in your Info.plist or startUpdatingLocation will not work.
//
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
[self performSelector:@selector(stopUpdatingLocationWithMessage:)
withObject:@"Timed Out"
afterDelay:30];
我有檢查,以確保locationServicesEnabled啓用。
我已將NSLoationWhenInUseUsageDescription屬性添加到info.plist文件。我需要添加或啓用任何服務還有其他任何屬性嗎?
我不能爲上帝的愛搞清楚我做錯了什麼。有人可以幫我解決這個問題。
btw會彈出授權警報? – 2014-10-06 16:34:58
授權警報不會彈出 – dogwasstar 2014-10-07 00:05:43
然後我猜didChangeAuthorizationStatus回調既不會被調用,對吧?該應用的位置服務已啓用? (設置/隱私/位置服務)您確定您向.plist添加了正確的密鑰嗎? – 2014-10-07 07:14:08