我正在創建需要在特定時間在後臺喚醒的應用程序。startUpdating LocationManager通過靜默推送通知
我曾嘗試:
UILocalNotification:但我不希望使用UILocalNotification,因爲它需要用戶交互輕按通知,並不僅僅是應用程序將被喚醒並啓動位置管理。
我也使用
[locationManager startUpdatingLocation];
啓用背景模式位置更新,這是行得通的,但它會佔用大量的電池。
所以使用全新的iOS 7的功能Silent pushNotification
和didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:
方法我要開始在後臺位置管理,
-(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;
}];
}
無聲推送通知是否正常工作,
有效載荷PushNotification:
{"aps" : {"content-available" : 1},"SilentPushId" : "07"}
但是這不會開始位置經理,請有人幫助我。
編輯:
如果這是不可能,請給我一些建議。
是您的應用程序成爲前景後,此通知解僱而無需用戶交互? – Mani
@iMani:不,它不會。 – Optimistic
它始終沒有在後臺啓動位置管理器,或者有時失敗,有時會在後臺啓動。 – Mani