I am creating an application that needs to wake up in the background at a specific time.
I tried:
UILocalNotification: But I do not want to use UILocalNotification because it needs to interact with the user to use the notification, and only the application will wake up and launch the location manager.
/ li>I also used [locationManager startUpdatingLocation];Modes Location with the background settings, this works, but it will take a lot of battery.
So, using the new iOS 7 method Silent pushNotificationand didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:, I need to run the location manager in the 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 works correctly,
Payload for PushNotification:
{"aps" : {"content-available" : 1},"SilentPushId" : "07"}
. , .
EDIT:
, , .