I am creating navigation based app for iOS 7, for it I am taking users location data, Using CoreLocation framework,
App requirement is to start getting users location in background at particular time, For that I have implemented Silent Pushnotification with didReceiveRemoteNotification fetchCompletionHandler:
method,
I have successfully implement this Using Silent Pushnotification & it Call startUpdatingLocation
and I am able to get location data in delegate method :
Using This Payload:
{"aps" : {"content-available" : 1},"SilentPush" : "4"}
I have enabled location
& remote notification
for Background mode:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
__block UIBackgroundTaskIdentifier bgTask =0;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[self.locationManager startUpdatingLocation];
}];
didUpdateLocations
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
lastLoc=[locations lastObject];
[logFile addLocObject:[NSString stringWithFormat:@"Loc: %@",lastLoc]];
}
But Problem is :
After Some Seconds delegate method of location class is stops and it will not send any data if device is moving, And when i talking app to foreground it will called 'didFinishLaunhing' method , So i guess os will kill app even Location is updating,
in Device Diagnostics & usage
i am getting following crash report:
Application Specific Information:
MockUpApp2[390] has active assertions beyond permitted time:
{(
<BKProcessAssertion: 0x145ac790> identifier: Called by MockUpApp2, from -[AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:] process: MockUpApp2[390] permittedBackgroundDuration: 40.000000 reason: finishTaskAfterBackgroundContentFetching owner pid:390 preventSuspend preventIdleSleep preventSuspendOnSleep
)}
Yesterday I have asked this question now I am able to startlocation manager in background through push notification,
So please anybody can give solution of this problem.
Thank you.
Note: If I am running app in debugging mode, means I run app through XCode & not stoping it or not disconnecting , app will run.. In this case app will not stop by OS.
EDIT 1
As per @Stephen Darlington Answer if i remove all backgroundfatcher like,
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
[self.locationManager startUpdatingLocation];
}
Now app will not call didUpdateLocations
even once, :(
What should i write in this method?
Edit 2
As per Apple Doc say:
If your app is suspended or not running, the system wakes up or launches your app and puts it into the background running state before calling the method.
SO , is app should run in background for long as i enabled location backgound mode ,?