从后台检查

时间:2018-10-31 13:25:56

标签: ios swift wkwebview

我在Android上有一个Webview,该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”? (检查我已经拥有的连接状态的代码)

2 个答案:

答案 0 :(得分:0)

在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")

}

答案 1 :(得分:0)

订阅UIApplication.willEnterForegroundNotification,并在连接被触发后立即检查连接。