菜鸟教程小白 发表于 2022-12-12 13:17:07

ios - iPhone应用后台下载


                                            <p><p>我正在制作一个接收持续更新(可能每天数百次)的应用,为了提供更好的用户体验,最好在后台下载这些更新。</p>

<p>看苹果的<sup>[ <a href="https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html" rel="noreferrer noopener nofollow">1</a> ]</sup> 文档 我需要将后台模式设置为“后台获取”。深入探索,您可以阅读有关 <code>application:performFetchWithCompletionHandler</code><sup>[ <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:performFetchWithCompletionHandler:" rel="noreferrer noopener nofollow">2</a> ]</sup> 函数声明:</p>

<blockquote>
<p>When this method is called, your app has up to 30 seconds of wall-clock time to perform the download operation and call the specified completion handler block... If your app takes a long time to call the completion handler, it may be given fewer future opportunities to fetch data in the future.</p>
</blockquote>

<p>问题是我们的下载<strong><em>将</em></strong>需要超过 30 秒的时间来下载,因此宁愿不面对 Apple 发送更新越来越少的愤怒,因此加剧问题!</p>

<p>那么,我能以某种方式做到这一点吗?</p>

<p>另外,我创建了一个粗略的实验,我创建了一个 <code>NSTimer:scheduledTimerWithTimeInterval</code> 来运行每分钟记录到控制台。这在模拟的 iPhone 上(已经运行了 30 分钟以上)以及当我将它放在手机上(一周以上)时都成功运行......为什么会这样!?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>由于 Apple 30 年代的义务,这可能很难做到。他们决定这样做是为了最终防止发生大下载,以免耗尽电池和数据计划。</p>

<p>您必须确定您确实需要在后台下载这么多数据(因为它需要这么长时间),而且每天要下载数百次!</p>

<p>我的意思是,当您的应用在(长)后台周期后进入前台时,它可能不会更新,这是正常情况。因此,您需要在应用程序进入前台时进行更新;只需要一次更新。否则,您应该退后一步,重新考虑更新过程。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - iPhone应用后台下载,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/27382933/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/27382933/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - iPhone应用后台下载