本文介绍了通过静默推送通知启动LocationManager的UpdateUpdatingLocation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在创建需要在特定时间在后台唤醒的应用。 我试过: UILocalNotification:但我不想使用 UILocalNotification ,因为它需要用户互动才能点击通知,而且只有app会唤醒并启动位置管理器。 我还使用 [locationManager startUpdatingLocation]; 启用后台模式位置更新,这是有效,但需要大量电池。 因此使用新的iOS 7功能 Silent pushNotification 和 didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:方法我需要在后台启动位置管理器, - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler { NSLog(@Receive fetchCompletionHandler中的RemoteNotification与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} 但这不会启动位置管理员,请有人帮帮我。 编辑: 如果不可能请给我一些建议。解决方案我已经成功实现了这个使用Silent Pushnotification&它调用startUpdatingLocation,我能够在委托方法中获取位置数据: 使用此有效负载: {aps:{content-available:1 },SilentPush:4 } 我启用了位置&后台模式的远程通知: - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult result)处理程序 { __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]]; } 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. 解决方案 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]];} 这篇关于通过静默推送通知启动LocationManager的UpdateUpdatingLocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-24 12:40