2014-04-10 42 views
0

repetedly叫我開發與定位和獲取座標成功然後我打電話web服務來存儲座標的應用程序,但是當我使用IOS 7.1設備則didupdatelocation方法不repeadly調用。這裏是我的代碼didupdatelocation不是在IOS 7.1

if ([CLLocationManager locationServicesEnabled]) 
    { 
     self.locationManager = [[CLLocationManager alloc] init]; 
     self.locationManager.pausesLocationUpdatesAutomatically=NO; 

     self.locationManager.delegate = self; 
     self.locationManager.desiredAccuracy=kCLLocationAccuracyBest; 
     [self.locationManager startUpdatingLocation]; 
    } 

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{ 
    if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive) 
    { 
     CLLocationCoordinate2D center; 

     center.latitude = [[locations objectAtIndex:([locations count]-1)] coordinate].latitude; 
     center.longitude = [[locations objectAtIndex:([locations count]-1)] coordinate].longitude; 

     _point = [[MKPointAnnotation alloc] init]; 
     _point.coordinate = center; 

     if(appDelegate.strVehicleType!=nil) 
     { 
      [self checkInternet]; 
     } 

     NSLog(@"Changed"); 

     [_locationManager stopUpdatingLocation]; 
    } 
    else 
    { 
     CLLocationCoordinate2D center; 

     center.latitude = [[locations objectAtIndex:([locations  count]-1)] coordinate].latitude; 
     center.longitude = [[locations objectAtIndex:([locations  count]-1)] coordinate].longitude; 

     _point = [[MKPointAnnotation alloc] init]; 

     _point.coordinate = center; 

     if(appDelegate.strVehicleType!=nil) 
     { 
      [self checkInternet]; 
     } 

     NSLog(@"Location Changed in Background") 
     ; 
     [_locationManager stopUpdatingLocation]; 
    } 
} 

我在上面的代碼repetedly在IOS 6和iOS 7試過位置更新,但不是在7.1更新,所以請任何人都知道那裏是問題?或者是他們使用任何不同的方法。

Thanx提前。

+0

查看我的iOS 7及以上版本解決方案。 http://stackoverflow.com/questions/18946881/background-location-services-not-working-in-ios-7/21966662#21966662有一篇博文和Github的完整解決方案。 – Ricky

回答

1

如果您使用模擬器進行測試,請重置模擬器。 如果您使用設備,然後從它刪除應用程序。

添加#import <CoreLocation/CoreLocation.h>框架在.h文件中

附加委託CLLocationManagerDelegate在.h文件中

在viewDidLoad中把下面的代碼

if ([CLLocationManager locationServicesEnabled]) 
{ 
    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.pausesLocationUpdatesAutomatically=YES; 

    locationManager.delegate = self; 
    locationManager.desiredAccuracy=kCLLocationAccuracyBest; 
    [locationManager startUpdatingLocation]; 
} 

====== 然後

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{ 
    if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive) 
    { 

     NSLog(@"Active"); 

    } 
    else 
    { 
     NSLog(@"Non Active"); 
    } 
} 

運行應用程序,它會給你提醒'A ppname」想用你的當前位置」,按‘確定’

如果您正在使用測試模擬器,那麼請採取下面的步驟:

從模擬器 調試的工具欄>位置>蘋果

採取這些步驟後,模擬器更改位置和方法將會調用。

+0

讓我試試這個... –

+0

否@Viky同樣的結果didupdatelocations不會被調用。 –

+0

我使用設備與iOS 7.1 –

1

是的,因爲後臺應用刷新已切斷設備讓...

轉到常規>「後臺應用刷新」>打開。

and 一般>「後臺應用程序刷新」>您的應用程序>打開。

解決您的問題

+0

背景應用程序刷新是我已經關掉它,然後把它變成了&然後測試但仍然相同的結果.. –

+0

應用程序殺死和再次重新啓動 – Deepesh

+0

並刪除此行[_locationManager stopUpdatingLocation];從您的代碼 – Deepesh