本文介绍了几秒钟后,应用程序在ios7中被操作系统杀死了应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在为 iOS 7 创建基于导航的应用,因为我正在使用用户位置数据,使用CoreLocation框架,I am creating navigation based app for iOS 7, for it I am taking users location data, Using CoreLocation framework,应用要求是在特定时间开始获取用户在后台的位置,为此我用 didReceiveRemoteNotification fetchCompletionHandler实现了静音推送:方法,App requirement is to start getting users location in background at particular time, For that I have implemented Silent Pushnotification with didReceiveRemoteNotification fetchCompletionHandler: method, 我已成功实施使用无声推送&它调用 startUpdatingLocation ,我可以在委托方法中获取位置数据:I have successfully implement this Using Silent Pushnotification & it Call startUpdatingLocation and I am able to get location data in delegate method :使用此有效负载: {aps:{content-available:1},SilentPush:4} {"aps" : {"content-available" : 1},"SilentPush" : "4"}我已启用 location &背景模式的远程通知: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]];} 但问题是:在某些秒之后,位置类的委托方法停止,如果设备正在移动它将不会发送任何数据,而当我说app应用于前台时,它会调用'didFinishLaunhing'方法,所以我猜操作系统将杀死应用程序甚至位置正在更新,设备诊断&中的用法我收到以下崩溃报告: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.谢谢。 注意:如果我在调试模式下运行应用程序,则意味着我通过XCode& amp;不停止或不断开连接,应用程序将运行..在这种情况下,应用程序不会停止操作系统。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. 编辑1 根据@Stephen Darlington回答如果我删除所有backgroundfatcher 之类的,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];}现在app不会调用 didUpdateLocations 甚至一次,:( Now app will not call didUpdateLocations even once, :(我应该用这种方法写什么?What should i write in this method? 编辑2 Edit 2根据 Apple Doc 说: 如果您的应用暂停或未运行,系统会唤醒或启动您的应用并将其置于后台运行状态,然后再调用方法。 所以应用程序应该在后台运行很长时间,因为我启用了位置背景模式,?SO , is app should run in background for long as i enabled location backgound mode ,?推荐答案我不认为iOS上的后台处理方式与您期望的方式相同。它不像在Mac上或Windows可以在backgrou中无限期运行nd(即使iOS 7中的更改)。I don't think background processing on iOS works in the way that you're expecting. It's not like on the Mac or Windows where you can run indefinitely in the background (even with the changes in iOS 7).因此,要直接回答您的问题:您启动可以继续在后台运行的任务。有两个但是。So, to directly answer your question: you kick off a task that can continue to run in the background. There are two "buts." 代码块是到期处理程序。 不您要在后台运行的代码。此代码将在后台任务超时之前执行(因此在您的情况下,它会在您的应用程序被杀之前不久执行)。苹果并没有真正记录多长时间,但它看起来好像你需要大约40秒。您想在后台运行的代码是 c> beginBackgroundTaskWithExpirationHandler 之后的行。当你完成后,你说 endBackgroundTask: 其次,位置更新在后台工作,没有全部 beginBackgroundTaskWithExpirationHandler:东西。即使应用程序在后台,也会调用委托方法 The code block is the expiration handler. It is not the code that you want to run in the background. This code will get execute just before the background task is out of time (so in your case it gets executed shortly before your app is killed). Apple doesn't really document how long that is but it looks as though you're getting about 40 seconds. The code you want to run in the background are the lines after beginBackgroundTaskWithExpirationHandler. When you're done you say endBackgroundTask:Secondly, location updates work in the background without all the beginBackgroundTaskWithExpirationHandler: stuff. The delegate methods will get called even if the app is in the background总结一下:删除 beginBackgroundTaskWithExpirationHandler: 声明。您只需要添加 startUpdatingLocation:。To summarise: remove the beginBackgroundTaskWithExpirationHandler: statement. You only need to add the startUpdatingLocation:. 这篇关于几秒钟后,应用程序在ios7中被操作系统杀死了应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-26 15:45