我剛剛更新到Xcode 6/iOS 8 SDK,我在模擬器中的位置服務模擬開始不起作用。我更新之前還好(我目前無法在真實設備上測試)。現在,當我選擇一個位置進行模擬時,沒有任何反應。代表的-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
方法未被調用。我重新啓動了Xcode,清理了構建文件夾,沒有任何改變。爲什麼會發生?Xcode 6/iOS 8位置模擬不起作用
8
A
回答
14
由於IOS 8在啓動CLLocationManager之前需要獲得授權。
你在調用這些方法嗎?
[self.locationManager requestWhenInUseAuthorization]; // For foreground access
[self.locationManager requestAlwaysAuthorization]; // For background access
如果您在XCode 6之前創建了項目,那麼您可能還需要爲新權限添加info.plist條目。
有關詳細信息看看這篇文章:Location Services not working in iOS 8
14
添加下面的代碼在你的方法
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[self.locationManager requestWhenInUseAuthorization];
}
還要添加下面一行在你info.plist
文件
重點:NSLocationWhenInUseUsageDescription
值:用途當前位置
0
其他答案是正確的,但我也必須重置模擬器be前面我可以找到一個位置,但它在設備上工作正常。該應用程序最初安裝在該模擬器的iOS 8
之前要重置模擬器:
2
使用的Xcode 6.3.1我有區位選擇停止更新。修復方法是運行另一個項目,選擇「模擬位置>不要模擬位置」,然後再次構建原始項目以恢復正常的位置設置。
0
- (void)startLocationUpdates{
geocoder = [[CLGeocoder alloc] init];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
}
// Reverse Geocoding
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
fullAddress = [NSString stringWithFormat:@"%@,%@,%@,%@",
placemark.thoroughfare,
placemark.locality,
placemark.administrativeArea,
placemark.country];
subtitleLocation = [NSString stringWithFormat:@"PostalCode::%@",
placemark.postalCode];
} else {
// NSLog(@"%@", error.debugDescription);
}
} ];
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error{
NSLog(@"Cannot find the location.");
}
相關問題
- 1. Xcode模擬器不起作用
- 2. xcode iphone模擬器不起作用
- 3. 模擬位置在Google地圖上不起作用
- 4. Xcode 8 - 模擬3DTouch和ForceTouch
- 5. xcode 8不包括ios 10模擬器
- 6. Python模擬不起作用
- 7. Xcode 8中的位碼錯誤,但僅適用於模擬器
- 8. 測試的模擬位置不工作
- 9. 檢測模擬位置不工作(Android)
- 10. 用戶位置不會出現在模擬器在Xcode
- 11. XCode:位置模擬器不會調用locationManager:didUpdateToLocation:FromLocation
- 12. 位置粘不起作用
- 13. iOS 8 MPMoviePlayerPlaybackDidFinishNotification不起作用
- 14. 我的Xcode模擬器的位置卡在自定義位置
- 15. xcode 8模擬器安裝後不顯示xcode 8.1
- 16. 核心位置在Xcode 7.3中不起作用
- 17. 在iOS模擬器的Xcode黑屏8
- 18. Xcode 8沒有iOS10模擬器
- 19. Xcode 8中沒有IOS 10模擬器
- 20. Xcode線環繞設置不起作用
- 21. WAMP虛擬主機錯誤日誌位置不起作用?
- 22. SpriteKit,XCode 8,Swift 3 MGGetBoolAnswer在模擬器中不可用
- 23. setMobileDataEnabled在模擬器上不起作用?
- 24. Chrome DevTools觸摸模擬不起作用
- 25. Spring模擬存儲庫不起作用
- 26. Android的SDK模擬器不起作用
- 27. iOS模擬器GPS不起作用?
- 28. android 5.0 arm模擬器不起作用
- 29. Genymotion Android模擬器不起作用
- 30. 模擬退火不起作用
有這個問題的任何人,我掙扎了一段時間,因爲我是用'[的LocationManager requestWhenInUseAuthorization]'的應用程序,但宣佈了'NSLocationAlwaysUsageDescription'中的.plist文件(注意區別「總是'和'在使用'這個解決方案,但確保你**聲明正確的用法描述類型**,NSLocationWhenInUseUsageDescription或NSLocationAlwaysUsageDescription(或者兩者都有) – 1owk3y 2015-05-27 00:26:00