question

Shivaprasad avatar image
Shivaprasad asked

IOS Push-notification not working IOS but works on Android.

Hi , We were following these links to add push notification to our cross platform project (IOS and Android).
https://docs.microsoft.com/en-us/gaming/playfab/features/engagement/push-notifications/quickstart

and

https://docs.microsoft.com/en-us/gaming/playfab/features/engagement/push-notifications/push-notifications-for-ios

We were able to easily setup for Android it worked very well with FCM.

But when we built the project for IOS using Unity's Package for Push notification. (As FCM is not supported for IOS)
https://docs.unity3d.com/Packages/com.unity.mobile.notifications@1.2/manual/index.html

----------------------------------------------------------Side Note------------------------------------------------------------
We also use this plugin because UnityEngine.iOS.NotificationServices.deviceToken was always null even after 3 seconds after calling UnityEngine.iOS.NotificationServices.RegisterForNotifications.
And having no proper callback we thought was not reliable any way to poll for the deviceToken, while not knowing whether RegisterForNotification was successful or not.

----------------------------------------------------------End of Side Note----------------------------------------------------

Then we ran into problem mentioned here

https://community.playfab.com/questions/15918/fcm-ios-push-notifications-arent-working-android-d.html

After that we were able to remove Firebase Messaging while building to IOS platform, even then we are facing same problem mentioned in above link.

But note that we are able to get notification on IOS device, via some service like
https://www.apnstester.com/apns/

Which makes us believe this might be a bug with Cross-platform message routing (PlayFab via Amazon Simple Notification Service [SNS]). As mentioned in Quickstart.


unity3dPush Notifications
9 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.

Sarah Zhang avatar image Sarah Zhang commented ·

We will try to reproduce it.

0 Likes 0 ·
Shivaprasad avatar image Shivaprasad Sarah Zhang commented ·

Thank you, Let me know if you have any luck solving the issue.

0 Likes 0 ·
Shivaprasad avatar image Shivaprasad commented ·

Any Updates on this guys?

0 Likes 0 ·
Shivaprasad avatar image Shivaprasad commented ·

Any Update on this?

0 Likes 0 ·
Shivaprasad avatar image Shivaprasad commented ·

Was this reproduced?

0 Likes 0 ·
Shivaprasad avatar image Shivaprasad commented ·

Any update?!

0 Likes 0 ·
Show more comments
Shivaprasad avatar image
Shivaprasad answered

Issue was cause by miss match in .pem file and singing certificate used.

10 |1200

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

Sarah Zhang avatar image
Sarah Zhang answered

We have followed this tutorial -- Push Notifications For iOS to test pushing notifications for iOS. It works fine, the alert message would pop up when the application starts. After users choose "allow to push notification", the application can go on. The Client API RegisterForIOSPushNotification and SendPushNotification both can work. We also test to use this sample with the Unity Mobile Notifications Plugin, it works fine too. You can try to refer to the following sample code.

using System.Collections;
using PlayFab;
using PlayFab.ClientModels;
using Unity.Notifications.iOS;
using UnityEngine;


public class TestNotification : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(RequestAuthorization());
    }


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


            string res = "\n RequestAuthorization: \n";
            res += "\n finished: " + req.IsFinished;
            res += "\n granted :  " + req.Granted;
            res += "\n error:  " + req.Error;
            res += "\n deviceToken:  " + req.DeviceToken;
            Debug.Log(res);


            PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest
            {
                CustomId = "[YourCustomId]",
                CreateAccount = true,
                TitleId = PlayFabSettings.TitleId


            }, OnLoginSuccess, OnPlayFabError);
        }


    }


    private void OnLoginSuccess(LoginResult obj)
    {
        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!");
        }
    }


    private void OnPlayFabError(PlayFabError error)
    {
        Debug.Log(error.GenerateErrorReport());
    }
}



For more advanced questions about Unity Notification Plugins, please navigate to the Unity forum for professional supports. For more information on how to send push notifications to a device and how to add push notification support to your app, see the Apple Developer website documentation.

3 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.

Shivaprasad avatar image Shivaprasad commented ·

This should actually be not working...Because on the latest XCode / IOS (13.x.x) give token description instead of token it self, in following format.

{ length = 32, bytes = 0xd3d997af 967d1f43 b405374a 13394d2f ... 28f10282 14af515f }

Please let me know if you are getting the token properly on IOS 13, i might be able to remove preview package of unity notification.

Also on Unity 2017.16
UnityEngine.iOS.NotificationServices.deviceToken;
is not byte[] rather it is string.

Also in playfab version wise documentation if this is maintained , that will be greate.

0 Likes 0 ·
Shivaprasad avatar image Shivaprasad commented ·

Correction it was Unity 2019.3.0

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Shivaprasad commented ·

The test environment is Unity 2019.3, the latest Xcode, iOS 10. Thanks for your sharing.

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.