Page Lifecycle events not working on ios

I’m developing an Ionic 2 application for ios and testing directly in IPhone 5S with XCode.

In a page typescript file I created the lifecycle functions ionViewDidLoad and ionViewDidLeave.

In both functions I placed a navCtrl.setRoot(OtherPage). When testing with ionic serve, the page automatically redirects to another page on entering. When testing in the real device the setRoot() is not called, on entering nor on leaving page.

The code is just like this:

ionViewDidEnter() {
    this.navCtrl.setRoot(Map);
}

ionViewWillLeave() {
    this.navCtrl.setRoot(Map);
}

I’ve tried with setRoot and with push. It works only in ionic serve, it seems the event itself is not triggered.
Is there any incompatibility with page lifecycle events when executing in ios?

Thanks in Advance!

Add a console.log inside the lifecycle events functions and see if they are called on the device or not:

Use remote debug to see the log output. Follow these instructions here to debug the problem in Safari dev tools: https://ionic.zone/debug/remote-debug-your-app#ios Look at the console tab.

What does that mean?

@Sujan12 Thanks for your answer!

I’ve inserted the page redirection and some other “logics” instead of logs in order to detect the triggering of the events, and it seems the events in fact aren’t being called. I may try with console.logs, but it probably won’t be different.

About push: I meant that I tried with both this.navCtrl.setRoot(Map) and this.navCtrl.push(Map)

@Sujan12
I put (only) logs in these two event functions and tested their behavior with Safari Inspector, as you recommended. In fact the functions are not called when executed in the IPhone :frowning:

These logs are printed when executed with ionic serve.

Are you using lazy loading? @Sujan12’s suggestion of inserting a console.log statement is important. I suspect you will see that it is actually entering, but your navigation logic is not working. (Edit - looks like you posted as I posted about console logs)

I suspect this isn’t a browser/device issue, but rather reliance on undefined behavior. Lifecycle events are probably triggered during navigation transitions, inside which new navigation transitions shouldn’t be initiated. IOW, I wouldn’t be surprised if calling setRoot() (or push()) from within either ionViewDidEnter() or ionViewWillLeave() simply results in unpredictable weirdness.

1 Like

Hm, that doesn’t really make sense and is unexpected. Is this page the rootPage? Do you navigate there? How?