Search code examples
c#iosxamarin.formspush-notificationvisual-studio-app-center

Appcenter push notifications not received by Xamarin Forms on iOS platform


I've implemented push notifications with AppCenter on an ASP.Net Core Web API. Server is sending HTTP requests to AppCenter that is in charge of pushing notifications to each platforms Android & iOS.

Mobile apps are developed with Xamarin Forms. I've followed Microsoft documentation here

Xamarin Android application is receiving every push notifications like a charm.

The problem is for Xamarin iOS application. Devices are not receiving any push notification.

Here is iOS settings I've made:

  • Enabled push notifications in Entitlements for production (not development)
  • Created an APN key for push notifications in my Apple developer account for production
  • Provided iOS APN key to AppCenter settings (with APP ID, Prefix...)
  • Enabled remote notifications in background mode in info.plist
  • Disabled swizzling by adding AppCenterAppDelegateForwarderEnabled key to info.plist
  • Overrided DidReceiveRemoteNotification in AppDelegate and implements methods RegisteredForRemoteNotifications , FailedToRegisterForRemoteNotifications

Then, I've successfully published the app to TestFligth in production mode.

When launching the app, I'm getting appcenter device InstallId by calling method AppCenter.GetInstallIdAsync().

Finally, when push notification is sent, nothing happens. And I don't have any logs to search the problem.

Is there something I missed to make it work ?


Solution

  • AppCenter provides a different AppSecret for each platform. You should do :

            if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.iOS)
            {
                //Start AppCenter Push notification with iOS app secret
                AppCenter.Start("xxxxxxxxxxxxxxxxxxxxxxx", typeof(Push));
            }
            else if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.UWP)
            {
                //Start AppCenter Push notification with UWP app secret
                AppCenter.Start("xxxxxxxxxxxxxxxxxxxxxxx", typeof(Push));
            }
            else if(Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.Android)
            {
                //Start AppCenter Push notification with Android app secret
                AppCenter.Start("xxxxxxxxxxxxxxxxxxxxxxx", typeof(Push));
            }