首页 > 解决方案 > 从后台检查

问题描述

我在 Android 上有一个 webview,它始终检查是否有互联网从后台返回,检查连接状态是否已更改,如果它处于脱机状态,则应用程序使用以下代码将用户发送到“重新连接并重试”屏幕:

protected void onResume() {
        super.onResume();
        mWebView.onResume();
        if (isConnected(getApplicationContext())){
        } else {
            Intent i = new Intent(MainActivity.this, off.class);
            startActivity(i);
            overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            finish();
        }
    }

到目前为止,我已经为这个 webview 的 ios 制作了一个版本,但是当应用程序从后台返回时我无法重现这个检查,我如何在 ios swift 中重现这个“onresume”?(检查我已经拥有的连接状态的代码)

标签: iosswiftwkwebview

解决方案


在 AppDelegate 中使用以下方法:

func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    print("Enter foreground")

}

推荐阅读