Reputation: 11
We implemented remote push notifications in our app. What we would like to achieve is that when our app is in the background, a remote notification comes in, the user clicks on the notification, we perform some tasks based on the notification information. I noticed that when the app was in the background, when a notification came in, in Appdelegate, DidReceiveRemoteNotification and ReceivedRemoteNotification never get called. There's no way for me to get the notification from userInfo. Has anyone experienced this issue? Is this a bug? Any help is greatly appreciated!
Thanks, Lichang
Upvotes: 1
Views: 1968
Reputation: 4652
Make sure that you are testing on a real device. You need to have this in your info.plist
:
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
and this in your Entitlements.plist
:
<dict>
<key>aps-environment</key>
<string>development</string>
</dict>
Have your AppDelegate
class implement this interface: IUNUserNotificationCenterDelegate
.
Try adding this and see if it gets called:
[Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
public void WillPresentNotification(UNUserNotificationCenter center,
UNNotification notification,
Action<UNNotificationPresentationOptions> completionHandler)
{
completionHandler?.Invoke(UNNotificationPresentationOptions.Alert);
}
public override void DidReceiveRemoteNotification(UIApplication application,
NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
//BACKGROUND
//handleNotification(userInfo);
completionHandler(UIBackgroundFetchResult.NewData);
}
Also, on the apple developer portal, make sure that you either have added something for Keys or an Apple Push Services certificate and you have the cert in the provisioning profile that is signing the app.
Upvotes: 1