Flutter and OneSignal, how to catch notification in different page than where it's initialized - flutter

I'm running init on the front page of my app:
OneSignal.shared.init("app-id");
And catching notifications and then doing something if app is in view:
OneSignal.shared.setNotificationReceivedHandler((OSNotification notification) {
// doing stuff here, works great on front page
}
That works fine in frontpage. But, I'd like to catch the notifications and do specific tasks on other pages as well, that however does not work.
Tried to use: setNotificationReceivedHandler in other pages, but no luck, it always uses the front page's setNotificationReceivedHandler instead.
Is this possible to achieve?

Ok, got it to work.
The whole init process has to be done in every view where you want to catch notification, the latest loaded init is the one which is being processed.

Related

Why would fireEvent work but userEvent not work?

In short, I have a table row with an onclick event. I am getting this via
const row = screen.getByRole('row', { name: /My row/i })
await userEvent.click(row)
This does not trigger the event handler. However, if I do:
const row = screen.getByRole('row', { name: /My row/i })
fireEvent.click(row)
This works fine.
I know userEvent uses more events to simulate a row click, but the event handler works fine in the live application too. Are there any reasons why userEvent might not work?
Like most very strange things, the problem lied elsewhere. But for documentation purposes, this was due to the app rerendering while doing my assertions. What would happen was this:
App renders, making a bunch of API calls
My API call for my test finishes, say, get user
findByText('My User') passes and gets me my DOM element
Another API call finishes, re-rendering the component to show this data
The result of findByText is no longer the current active DOM element
click fires
As its no longer in the document, there's nothing to click/fire an event
I changed my previous lines to check for ALL data loads before grabbing my row and it seems to consistently be working. This means I have to assert things unrelated to my tests, but that may be due to my app having poor UX with things popping in as they load?
Either way, I'm not 100% confident this is the reason, but if
userEvent.click is not firing events, or
toBeInTheDocument is failing, even if findBy worked
It may be due to your app rerendering after you've asserted everything has loaded. Hope I can save someone else 3 days of suffering like I had to to find that simple fact...

How to do fast controller initialization

In my application with GetX, I had to create around 7 controllers, and they need to be initialized.
Everything works fine, but the controller I created for mobile ads sometimes throws an error. Actually, it does not give an error, but a bug occurs.
The problem is that when the app opens, it needs to show ads on the first click. As soon as the application is opened, when you click quickly, it does not show the interstitial ad. But a few seconds pass and if clicked, it shows the ad.
I'm not writing here because I don't have a problem with the codes. Is there any method I can solve this?

Black screen page on apple watch apps with more that one page

Hi I have created a Watch app which has two pages but when I run it on apple watch and do switch between pages after few seconds one page(sometimes page1 and sometimes page2)goes black and It doesn’t show my buttons, labels nothing. But when I run it on simulator there is no problem everything is fine and also before i add second page to the app It was ok on apple watch too
I had the same issue and it was due to calling crownSequencer.focus() without a corresponding crownSequencer.resignFocus() call. In my case I was calling focus() in didAppear() and once I added a resignFocus() call to willDisappear() the problem went away.
I guess if you remove override function didDeactivate() from both interfaceControllers may solve the problem but that's when you don't need this function and if you do try user899076 answer.
remove this:
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}

Initializing component inside a home page in Ionic4

I have a Home Page, inside that I have created one component RecentlyViewedProductComponent.
My problem is:
when I navigate to /home by using
this.router.navigate(['/home']);
the ngOnInit() inside RecentlyViewedProductComponent is not working. When I close the app and open it again, that only it is working .
How to solve this problem?
It sounds like you are not using the right lifecycle event.
Have you looked at the documentation here:
https://ionicframework.com/docs/angular/lifecycle
It says that ngOnInit() is:
Fired once during component initialization. This event can be used to initialize local members and make calls into services that only need to be done once.
If you want it to be called every time you navigate to the home page then you want to replace this with something like ionViewWillEnter():
Fired when the component routing to is about to animate into view.
There is actually some guidance at the end of the docs page that you might find interesting which explains when to use each life cycle method.

How to know UIWebView won't load anymore?

I know that there are delegate methods.
In my case, the scenario is little bit different. When I load my request, there are subsequent calls that happens. So the page get loaded back to back with 3 urls. After that, it stops.
When it is done loading everything, after that actually I wanted to do something like 'autosubmit', which is not possible for mobile browsers. I am looking for a work around. But for that too, I need to make sure that the webView has done loading.
So my question here is, is there any proper way to find out that the web view has finally stopped loading, and then I can try something to do my 'autosubmit' part?
I have an answer to the detecting when the web view is done loading part of your question... Unfortunately, the most reliable method I have found is to increment a counter whenever webViewDidBeginLoad: is called and decrementing it whenever webViewDidFinishLoading: and webViewDidFailWithError: is called. Whenever the counter is equal to 0 you know that the web view is not loading.
Placing this check in the webViewDidFinishLoading: and webViewDidFailWithError: methods will allow you to determine when the web has completed or stopped loading (in the case of a failure).