I am creating app that needs to wake up in background at particular time .
I have tried :
UILocalNotification : But i Don't want to use UILocalNotification because it needs user interaction to tap on notification and than only app will wake up and start location manager.
I have also used
[locationManager startUpdatingLocation];
enabled with background Modes Location updates, this is works but it will take lot of battery.
So with using new iOS 7 feature Silent pushNotification
and didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:
method i need to start location manager in background,
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
NSLog(@"Receive RemoteNotification in fetchCompletionHandler with UserInfo:%@",userInfo);
application.applicationIconBadgeNumber=0;
__block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
[self.locationManager startUpdatingLocation];
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
}
Silent Push notification is working correctly ,
Payload for PushNotification:
{"aps" : {"content-available" : 1},"SilentPushId" : "07"}
But this will not start location manager , Please somebody help me.
EDIT:
If it is not possible please give me some suggestions.
If you want to update location in background mode, you just enable UIBackgroundModes in plist file. See startUpdatingLocation description in apple's doc..
You can enable this for background updation in your xcode5+ as like below..
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:
I have enabled location & remote notification for Background mode:
didUpdateLocations
You cannot. It is explicitly not permitted to start location services while the application is in the background. The user has to be aware of the start with the app open.
Imagine what subversive tracking would be available if you could send silent notifications to trigger a location update back to a server without the user knowing about it...
What you can do, in background, is receive significantLocation events and boundary events. I can imagine leveraging that capability to keep a recent locations log of sorts. When your remote notification is received, respond by sending last known location. With a bit of experimentation I am sure you could refine this to be reasonably accurate with little impact on the battery.