【问题标题】:How to Call an API in applicationWillTerminate( ) and get some time for response from the server如何在 applicationWillTerminate() 中调用 API 并获得服务器响应的时间
【发布时间】:2021-09-03 05:07:06
【问题描述】:

抱歉重复问题,经过长期研究“如何在 applicationWillTerminate() 中调用 Api”的问题,但一无所获。有两种解决方案,但有些方法对我不起作用。找到的解决方案:Can I make an api call when the user terminates the app?

【问题讨论】:

  • 我不相信您会找到可靠的解决方案。请记住,在许多情况下,尤其是当用户从切换器向上滑动您的应用时,applicationWillTerminate 不会被调用
  • 终止应用程序就像 macOS 中的强制退出。在这两种情况下,applicationWillTerminate 都不会被调用。在 iOS 中,无论如何建议立即保存更改。

标签: ios api applicationwillterminate


【解决方案1】:

如果您的应用处于 applicationWillTerminate 状态或应用处于终止状态,则您无法调用 API。

应用程序只允许在 applicationWillTerminate 状态中保存即时更改

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
CoreDataManager.sharedManager.saveContext()
}

【讨论】:

    猜你喜欢
    • 2014-03-25
    • 2018-05-27
    • 2014-08-14
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多