Ionic app activity suspended when InAppBrowser is opened


#1

I want to open and close an InAppBrowser programatically when the app receives some socket events.

But I noticed all events handling appears to be paused when InAppBrowser is being shown.

Therefore I can only open an InAppBrowser, but I cant close it programmatically because I can no longer receive any events when InAppbrowser is showing.

Here is a simplified version of my code, to demonstrate the problem:

export interface PageInterface {
  title: string;
  name: string;
  component: any;
  icon: string;
  logsOut?: boolean;
  index?: number;
  tabName?: string;
  tabComponent?: any;
}

@Component({
  templateUrl: 'app.template.html'
})
export class MyApp {
  @ViewChild(Nav) nav: Nav;
  appPages: PageInterface[] = [... ];
  loggedInPages: PageInterface[] = [... ];
  loggedOutPages: PageInterface[] = [...];
  rootPage: any;
  browser: any;

  constructor(
    public events: Events,
    public userData: UserData,
    public menu: MenuController,
    public platform: Platform,
    public confData: ConferenceData,
    public parseData: ParseData,
    public storage: Storage,
    public splashScreen: SplashScreen,
    private iab: InAppBrowser
  ) {

    this.rootPage = TabsPage;
    this.platformReady()

  }

  openPage(page: PageInterface) {
    ...
  }

  platformReady() {
    // Call any initial plugins when ready
    this.platform.ready().then(() => {
      this.splashScreen.hide();

      setInterval(() => {
        // !!!!!
        // this tick paused when inappbrowser is launched, why?
        // !!!!!
        console.log("tick");
      },500);

      setTimeout(() => {
        console.log("time out fired, launch iab!");
        this.browser = this.iab.create("https://www.google.com","_blank");
      },3000);

    });
  }

  isActive(page: PageInterface) {
     ...
  }
}

In this demo, we run a setInterval loop that prints a log every 500ms, and launch an InAppBrowser after 3 seconds.

The loop paused when InAppBrowser is showing.

This problem appears to be only happening on actual device. it works on simulator.

Why?


#2

Help, anyone?

I need to know, where should I write a piece of code that will continue running even if an InAppBrowser is opened? I suspect InAppBrowser is a new UIWindow itself.

If I were write native iOS app I will most likely write the looping code/event handling codes in AppDelegate. Where is the AppDelegate’s equivalent in Ionic2?