question

matias avatar image
matias asked

iOS Push Notification Not Working

Hi, i'm working on Unity Game using playfab. Currently the push notification system is working on Android but its not working on ios. I've followed the documentation from Playfab

What i've done:
- Create a Certificate for "Apple Push Notification service SSL (Sandbox and production)




- I've created the .pem from a .p12 and set it in playfab settings

- I've set my xcode proyect to use push notifications

- I've use the following code from Playfab doc:

UnityEngine.iOS.NotificationServices.RegisterForNotifications(UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Sound, true);byte[] token = UnityEngine.iOS.NotificationServices.deviceToken;
if(token != null)
{
    RegisterForIOSPushNotificationRequest request = new RegisterForIOSPushNotificationRequest();
    request.DeviceToken = System.BitConverter.ToString(token).Replace("-", "").ToLower();
    PlayFabClientAPI.RegisterForIOSPushNotification(request, (RegisterForIOSPushNotificationResult result) =>
    {
        Debug.Log("Push Registration Successful");
    }, OnPlayFabError);
}
else
{
    Debug.Log("Push Token was null!");
}

- I've change that code to a new one since the other said it was deprecated

IEnumerator RequestToken()
    {
        const AuthorizationOption AUTHORIZATION_OPTION = AuthorizationOption.Alert | AuthorizationOption.Badge | AuthorizationOption.Sound;
        using (var req = new AuthorizationRequest(AUTHORIZATION_OPTION, true))
        {
            while (!req.IsFinished)
            {
                yield return null;
            }


            if (req.Granted && req.DeviceToken != "")
            {
                RegisterForIOSPushNotificationRequest request = new RegisterForIOSPushNotificationRequest();
                request.DeviceToken = BitConverter.ToString(Encoding.UTF8.GetBytes(req.DeviceToken)).Replace("-", "").ToLower(); ;


                PlayFabClientAPI.RegisterForIOSPushNotification(request, (RegisterForIOSPushNotificationResult result) =>
                {
                    Debug.Log("Push Registration Successful");
                }, error => { });
            }
        }
    }


I've been testing it from a direct install and testflight but no notification show when i send it from my server

Push Notificationsentities
idlrb.png (10.6 KiB)
pa1ua.png (54.0 KiB)
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Xiao Zha avatar image Xiao Zha commented ·

May I ask if your app is in the background or is it active? If the app is active, the notification will be received silently and will not be visible in the notification area. And if the app is in the background, the notification will be routed to the Notification area. In addition, you may follow the IOS troubleshooting steps to confirm you have set the Notification properly.

0 Likes 0 ·
matias avatar image matias commented ·

@Xiao Zha

I've tried with the app active, bg and close none of them worked. I've also checked the iOS troubleshooting but didn't help either.
I've tried using Firebase Cloud Messaging and its working great with iOS... Any chance i can use it to send my notification from PlayFab like i do with Android

0 Likes 0 ·

1 Answer

·
matias avatar image
matias answered

Manage to fix it, i've remove the initialization from firebase push notification entirely and it worked perfectly in testflight

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Xiao Zha avatar image Xiao Zha commented ·

Glad to hear your issue resolved. If you have any other questions, please feel free to post a new thread for it.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.