菜鸟教程小白 发表于 2022-12-13 05:36:33

ios - 如何从 Kill 状态重新启动我的 iOS 应用程序以执行长时间任务?


                                            <p><p>首先我将解释我想要实现的目标。
我有一个BLE锁。我希望我的应用程序将从终止状态中唤醒并开始扫描 BLE 设备。找到 BLE 设备后,它将与我的手机连接并解锁。</p>

<p>所有这些都在后台模式下工作,我测试了很多次。但我也希望这在应用程序处于终止状态时能够工作。</p>

<p>我尝试了几件事。首先,我尝试了地理围栏,但如果地理围栏应用程序唤醒时间较短,我无法正确扫描 BLE 设备。当 <code>didEnterRegion region:</code> 调用时,我发送了本地通知,它工作正常。因此,之后我尝试在 <code>didEnterRegion region:</code> 时扫描 BLE 设备,并且还收到扫描已开始的通知,但我认为一段时间后应用程序会自动从后台删除并且无法重新启动。所以这就是我没有发现任何 BLE 设备的原因。</p>

<p>我还阅读了 Core BlueTooth 的苹果文档:
<a href="https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html" rel="noreferrer noopener nofollow">https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html</a> </p>

<p>有人提到如何执行诸如打开和关闭门锁之类的长时间任务,但对我没有帮助。</p>

<p>请指导我在应用处于终止状态时如何执行此操作。</p>

<p>感谢您的帮助:)</p>

<p><strong>更新:</strong>
我的意思是杀死状态是暂停/终止/从后台删除。我只希望一旦用户进入地理围栏区域,然后应用程序在后台启动并开始扫描 BLE 设备。所以在那之后我希望应用程序将留在后台直到门解锁。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>正如 Paulw11 所述,一旦应用被用户终止/杀死,就无法在后台重新启动应用。 Apple 出于安全和功能原因故意这样做:如果用户因为某个应用程序存在错误/故障而故意终止该应用程序,则该应用程序应该无法自行重新启动。</p>

<p>更多信息可以在这里找到:-</p>

<ul>
<li> <a href="https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html" rel="noreferrer noopener nofollow">Core Bluetooth Background Processing for iOS Apps</a> </li>
<li> <a href="https://stackoverflow.com/questions/39353262/ble-device-keep-connect-with-iphone-when-application-terminate/" rel="noreferrer noopener nofollow">BLE device keep connect with iPhone when application terminate</a> </li>
</ul>

<p>我希望这会有所帮助。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何从 Kill 状态重新启动我的 iOS 应用程序以执行长时间任务?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/57424206/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/57424206/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何从 Kill 状态重新启动我的 iOS 应用程序以执行长时间任务?