I'm creating a Xamarin.iOS application that includes push notifications.
I've noticed that if the app is not running (not just at the background), when a push notification arrived (with the correct payload), the OS will take over handling the notification and will present it to the user and if the user clicks on the notification while it closed, I will be able to get this information from the NSDictionary options parameter of the FinishedLaunching method (finding if it contains the UIApplication.LaunchOptionsRemoteNotificationKey key)
so far, everything is great.
but I have two scenarios,
1) the push notification arrives when the application is running. 2) the user clicked on a push notification that arrived earlier (while the app was closed) after he launches the app
for both scenarios, the method ReceivedRemoteNotification is invoked.
but for each scenario I want to do a different business logic, my question is: How do I know if the ReceivedRemoteNotification was invoked by scenario 1 or scenario 2?
I've new to Xamarin and I've searched the web for it, but couldn't find a solution.
can anyone help me with this?
Thanks.
check the application state using the following condition, inside didReceiveRemoteNotification method,
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateBackground || state == UIApplicationStateInactive)
{//write here...Application opened by tapping notification}
FYI- The above code is in Objective-c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With