So I'm developing an app in Xamarin iOS and it requires push notifications be sent to update the offline sync'd data sporadically. However it seems that the DidReceiveRemoteNotification function only runs when the app is in the foreground!
I understand that it won't work if the app is closed but it should work while in the background right? The documentation seems to support this too. Through my own research, I can see that Native apple code has two different DidReceiveRemoteNotification's functions (didReceiveRemoteNotification and didReceiveRemoteNotification:fetchCompletionHandler) and the latter is used for handling background pushes. I'm really stuck as everything seems to suggest it should call it but it just doesn't.
Here's my function:
public override async void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult>
completionHandler)
{
Debug.WriteLine($"Notifcation Received - {userInfo.ToString()}");
//Call to an empty Azure function to prove it is being called!
//This allows me to check whether or not this code is eecuted without breakpoints in VS
using (HttpClient client = new HttpClient())
await client.GetAsync(FUNCTION_URL);
//.. My code to pull latest data here
completionHandler(UIBackgroundFetchResult.NewData);
}
And all I am sending it is a simple: "{\"aps\": {\"content-available\": 1 }}";
Background mode is set in the info.plist too
Can anyone point me in the right direction? Thanks!