2011-07-20 35 views
0

我嘗試更新用戶當前位置時,遇到了錯誤,我的相關代碼是這樣的:試圖更新位置

#pragma mark- 
#pragma mark CLLocationManagerDelegate 
-(void)locationManager:(CLLocationManager *)manager 
didUpdateToLocation:(CLLocation *)newLocation 
fromLocation:(CLLocation *)oldLocation 
{ 
    float latitude=newLocation.coordinate.latitude; 
    float longitude=newLocation.coordinate.longitude; 
    TopStationAppDelegate *topStation=(TopStationAppDelegate *)[[UIApplication sharedApplication]delegate]; 
    topStation.latitudeUtilisateur=latitude; 
    topStation.longitudeUtilisateur=longitude; 
    NSLog(@"%f",latitude); 
    NSLog(@"%f",longitude); 
    NSLog(@"position updated"); 
    //[locationManager stopUpdatingLocation]; 

} 
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
    NSLog(@"didFailWithError: %@", error); 
} 

didFailWithError方法返回我這個堆棧:

ERROR,Time,332840118.515,Function,"void CLClientHandleDaemonDataRegistration(__CLClient*, mach_port_t, const CLDaemonCommToClientRegistration*, const __CFDictionary*)",server did not accept client registration 2 
2011-07-20 09:35:18.525 TopStation[764:207] didFailWithError: Error Domain=kCLErrorDomain Code=1 "The operation couldn’t be completed. (kCLErrorDomain error 1.)" 

可以請你幫我嗎? thanx)

+0

你在模擬器上工作嗎? –

+0

是的,我目前在模擬器上測試:) – Malloc

+0

cllocationmanager不能在模擬器上工作這就是爲什麼你得到這個錯誤 –

回答

2

正如前面的評論所述,您正在使用的模擬器版本不適用於基於位置的東西。你最好的選擇(如果你是一個付費開發者)是下載新的Xcode 4.2,它允許你操作位置數據並且真正使用模擬器。

如果您不是付費開發者,則必須在設備上進行測試。

檢查這個職位here一些鏈接,如果你是一個付費的開發。您可以查看關於如何使用模擬器進行位置測試的WWDC視頻。