ios - 如何在 applicationWillTerminate 方法中调用 Web 服务并停止 VPN 服务器?

标签 ios objective-c xcode web-services vpn

我已经实现了 VPN 服务器逻辑 (NETunnelProviderManager) 并使用 startTunnel(options: ["ipv4": dnsIpv4]) 方法在 NETunnelProviderSession 上启动隧道。 VPN 工作正常并正常启动。我想在应用程序终止时在 applicationWillTerminate(_ application: UIApplication) 方法中停止 VPN 隧道。我也为此添加了代码逻辑,但它不会停止 VPN 而且我还想在应用程序终止时调用 API(Web 服务)。

func applicationWillTerminate(_ application: UIApplication) {

//停止VPN self.vpnService.disable {(错误)在

//执行API调用 self.myAPI()

最佳答案

Your implementation of this method has approximately five seconds to perform any tasks and return. If the method does not return before time expires, the system may kill the process altogether.

来源:https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623111-applicationwillterminate

关于ios - 如何在 applicationWillTerminate 方法中调用 Web 服务并停止 VPN 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47795437/

相关文章:

ios - 没有要编译的体系结构(ARCHS=armv7、armv7s、VALID_ARCHS=armv7 armv7s)

ios - 连接到 XCode 后,iPhone 位置服务显示错误的位置

ios - 使用 dequeueReusableCellWithIdentifier 时无法显示 detailTextLabel

xcode - Yosemite Xcode 6.1 build设置崩溃

ios - Xcode Analyzer - 忽略 CocoaPods 目标

ios - 如何将日期选择器的最短日期设置为从今天往前一个月

ios - Quickblox iOS - 在新 SDK 中创建用户时出错

objective-c - SingleTouch-View 中的第二根手指触发 touchesMoved

ios - Base64 到给定格式的图像

ios - 在设置应用程序中看不到MyAppNotificationSettings选项