I have a Xamarin.iOS app working that can successfully receive an APNS push notification when the app is running in the foreground. However, I also want to be able to handle the push notification when the app is running in the background, or not running at all.
This page on Xamarin appears to say that you can indeed do this:
I am using the Remote Notifications strategy outlined above. So I implemented exactly what it said, including changing the info.plist to have Remote Notifications as a background operation. However, I do not get any calls either in the DidFinishedLaunching, or ReceivedRemoteNotification callbacks when the app is running in the background. When the app is running in the foreground, everything works just fine. Needless to say, it's super frustrating.
Has anyone else run into this problem?
Any help is much appreciated!
Here is the code I am using to register for the remote notifications:
public static void NotifyAppStart()
{
if (GetRemoteWipePreference())
{
if (Utils.CheckOsVersion(8, 0))
{
// iOS 8 version
UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, new NSSet());
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
}
else
{
// Only works on iOS 7 and earlier
UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
}
}
}
And here is the PushSharp code I am using to send the push notifications on the server side:
push.RegisterAppleService(new ApplePushChannelSettings(appleCert, GetApplePwd() ));
push.QueueNotification(new AppleNotification()
.ForDeviceToken( token ).WithContentAvailable(1)
.WithCustomItem(msg, device.device_local_guid) );
Side note: There are a few other questions on stack overflow about this general area, but none of them actually are about this issue.
Aucun commentaire:
Enregistrer un commentaire