简体   繁体   中英

Location update not working in background mode iOS 7.0 in iPhone4s and iPhone5 while iPhone in ideal

i am working on one tracking application in that i use location manager service and

set desiredAccuracy = kCLLocationAccuracyNearestTenMeters

and distanceFilter = 60.0.

i want to give background support. for that i

set App registers for location updates,

App downloads content from the network

in my info.plist. and i put

[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];

this code in didFinishLaunchingWithOptions method.

i also use this method for call startUpdatingLocation location manager method

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

this all work in iOS 7 with iPhone4

but i have other two device in iPhone4S and iPhone5 in that device when device is ideal at that time application is in background so the navigation symbol get disappear and my location data not get updated on server.

when phone is ideal and when i start my application its not in background my application start from login screen.

so background location update not work for iPhone5 and iPhone4S having iOS7.

Please provide me solution for this.

my application is for tracking purpose if i am not get updated location so it is useless.

you can add this methods in your AppDelegate.m

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        NSLog(@"ending background task");
        [[UIApplication sharedApplication] endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];

    timer = [NSTimer scheduledTimerWithTimeInterval:5
      target:locationManager
      selector:@selector(startUpdatingLocation)
      userInfo:nil
      repeats:YES
    ];
}

you can take help with below link: Start Location Manager in iOS 7 from background task

to get your location update at interval of every 5 minutes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM