1

I have a webview on Android that always checks if there is internet coming back from the background checking if the connection status has changed if it is offline the application sends the user to a "reconnect and try again" screen using the code below:

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();
        }
    }

So far I have made a version for ios of this webview but I could not reproduce this check when the app returns from the background, how do I reproduce this "onresume" in ios swift? (the code that checks the connection state I already have)

denis
  • 129
  • 1
  • 6
  • check this event applicationDidBecomeActive(_:) https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622956-applicationdidbecomeactive or this https://stackoverflow.com/a/3639903/986169 – giorashc Oct 31 '18 at 13:31

2 Answers2

0

In AppDelegate use the following method:

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

}
Kai
  • 2,529
  • 1
  • 15
  • 24
  • I have an if that checks the connection as implement within that applicationWillEnterForeground ? – denis Nov 03 '18 at 23:46
0

Subscribe for UIApplication.willEnterForegroundNotification and check the connection immediately after it's fired.

kelin
  • 11,323
  • 6
  • 67
  • 104