0
votes

I have a strange issue. I am using azure notifications hub to push notifications to my Xamarin forms app (iOS). Everything works except for one specific case:

This works:

Case 1:

App is running -> push notificaiton is sent -> I get it in DidReceiveRemoteNotification callback -> I then show a popup (good)

Case 2

App is suspended and run in the background -> push notification is sent -> I get notoifcation on my phone at the top and red badge updates agains the app icon ->

if user taps notification at the top, app opens up and I get DidReceiveRemoteNotification event (good)

if user ignores the notification and just taps on the app icon -> NOTHING HAPPENS ???

I need to capture this notification somehow and I don't know why it is not showing. I have been googling for a while now to no avail.

What I have:

I have "Remote notificaitons" and "Background fetch" ticked in background modes

I am sending message like this: {"aps":{"alert":"Notification Hub test notification", "badge": 1}}

Why is it not triggering when user taps the app icon and not the notification and how do I get hold of this notificaiton in the app??? What am I missing

1

1 Answers

2
votes

If you want your app to be notified when a notification is received while being in background you need to set the Background Fetch as you have already done but also your notification should payload should include the key "content-available" as true.

{
    "aps" : {
        "content-available" : 1,
        "alert": "We have something great for you!!"
    },
    "content-id" : 1015
}

When the system (iOS) receives a notification for your app with this value it will wake it up (in background) and you will have 30 seconds to fetch any information you might need to update.

The delegate method that will handle this event is DidReceiveRemoteNotification

From the example payload above you will get the value of the "content-id" and fetch data from your server if you need.

You can also do silent notifications which is like the above but you omit the alert. With this you can tell your app to update the content and then if you need to notify the user you just use a local notification.

You can get more information about this here.