ios - 应用程序在后台保持几分钟后被杀死
<p><ul>
<li><p>当我打开我的应用并做一些事情时(比如导航到某个
<code>ViewController</code>),然后我有几分钟不触摸应用 iPhone 被锁定(应用进入 <code>BackGround State)</code>。</p></li>
<li><p>现在
分钟(大约 5 分钟)当我解锁 iPhone 我的应用程序被杀死了。
不在打开状态(<code>事件状态</code>)。我需要通过单击应用程序图标来明确打开它。</p></li>
<li>我没有在 <code>BackGround State</code></li> 做任何事情
<li>还有一点要补充的是应用没有崩溃</li>
</ul></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>如果您正确检查了您的应用程序没有崩溃,它会显示在多任务 UI 中,而您不是 <a href="https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html" rel="noreferrer noopener nofollow">executing code in the background</a> ,那么我会说您的应用程序正在被系统终止(由于内存压力或其他原因)。 </p>
<p> <a href="https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html#//apple_ref/doc/uid/TP40007072-CH2-SW7" rel="noreferrer noopener nofollow">Apple's documentation</a>提及:</p>
<blockquote>
<p>Apps must be prepared for termination to happen at any time and should
not wait to save user data or perform other critical tasks.
System-initiated termination is a normal part of an app’s life cycle.
The system usually terminates apps so that it can reclaim memory and
make room for other apps being launched by the user, but the system
may also terminate apps that are misbehaving or not responding to
events in a timely manner.</p>
<p>Suspended apps receive no notification when they are terminated; the
system kills the process and reclaims the corresponding memory. If an
app is currently running in the background and not suspended, the
system calls the <code>applicationWillTerminate:</code> of its app delegate prior
to termination.</p>
</blockquote>
<p>所以在您的场景中发生的情况是应用程序进入了暂停状态,并且在一段时间后(您提到的那 5 分钟)应用程序被系统终止了。<br/>
看看<a href="https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforHandlingAppStateTransitions/StrategiesforHandlingAppStateTransitions.html#//apple_ref/doc/uid/TP40007072-CH8-SW24" rel="noreferrer noopener nofollow">Background Transition Cycle</a> .</p>
<p>如果您想减少应用程序因内存压力而终止的可能性,请查看 <a href="https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforHandlingAppStateTransitions/StrategiesforHandlingAppStateTransitions.html#//apple_ref/doc/uid/TP40007072-CH8-SW22" rel="noreferrer noopener nofollow">What to Do When Your App Enters the Background</a> ,具体来说:</p>
<blockquote>
<p><strong>Free up memory as needed.</strong> Release any cached data that you do not need
and do any simple cleanup that might reduce your app’s memory
footprint. Apps with large memory footprints are the first to be
terminated by the system, so release image resources, data caches, and
any other objects that you no longer need. For more information, see
Reduce Your Memory Footprint.</p>
</blockquote></p>
<p style="font-size: 20px;">关于ios - 应用程序在后台保持几分钟后被杀死,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35551294/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35551294/
</a>
</p>
页:
[1]