菜鸟教程小白 发表于 2022-12-12 21:09:22

ios - ios7如何在后台运行进程


                                            <p><p>我想在前台和后台连续运行我的进程。我已经实现了以下代码</p>

<pre><code>self.updateTimer = [NSTimer scheduledTimerWithTimeInterval:10.0
                                                    target:self
                                                selector:@selector(repeatedMethod)
                                                userInfo:nil
                                                   repeats:YES];

self.backgroundTask = [ beginBackgroundTaskWithExpirationHandler:^{
    NSLog(@&#34;Background handler called. Not running background tasks anymore.&#34;);
    [ endBackgroundTask:self.backgroundTask];
    self.backgroundTask = UIBackgroundTaskInvalid;
}];
</code></pre>

<p>在前台很好,但在后台进程只运行了 5 分钟,并且运行时间不超过 5 分钟。但我希望它即使在后台也能连续运行。请帮助。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>发生这种情况,因为完成处理程序在 5 分钟后被调用。在使用 <a href="https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html" rel="noreferrer noopener nofollow" title="UIBackgroundModes">UIBackgroundModes</a> 之一之前,您无法在 iOS 中无限期地运行后台进程。这也取决于如果您在应用程序中使用它,您必须提供 BackgroundMode 的功能,否则苹果会拒绝它。</p>

<p>例如,如果您使用“VoiP”BackgroundMode,您的应用程序应提供“VoiP 服务”,否则将被拒绝</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - ios7如何在后台运行进程,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/22756480/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/22756480/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - ios7如何在后台运行进程