cmartin avatar image
cmartin asked

iOS push notification permission issue

I'm trying to get push notifications working on iOS (title E8F4). I had no issues registering our title using the .pem file. Here is the class I use in Unity:

using UnityEngine;
using System.Collections;
using PlayFab;
using PlayFab.ClientModels;

public class PlayFabController : MonoBehaviour
    public string titleId;
    bool tokenReceived = false;

    void Start()
        PlayFabSettings.TitleId = titleId;

    IEnumerator RegisterForPushNotifications()
        UnityEngine.iOS.NotificationServices.RegisterForNotifications(UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Sound, true);
        WaitForSeconds oneSec = new WaitForSeconds(1f);

        while (!tokenReceived)
            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");

                }, (error) =>
                    Debug.Log("Push Registration Failed with error: " + error.ErrorMessage);

                tokenReceived = true;
            yield return oneSec;
        yield return null;

When users start the app, they are prompted as expected to give permission. However, I've made a segment with the conditions "Push notifications enabled with ApplePushNotificationService" and the count is 0.

What am I missing?


Push Notifications
10 |1200

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

1 Answer

brendan avatar image
brendan answered

Looking at your title's dashboard, I see zero calls to RegisterForIOSPushNotification in the last 7 days. Can you give us an example of a player in the game that has registered for push notifications on that platform?

10 |1200

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

cmartin avatar image cmartin commented ·

I see! Well there should have been many over the last week, so perhaps something is wrong with my script. I'll look into it some more.

On a related note, if a user has given permission but the API call didn't work, is there some way to fix that retroactively or to prompt the user for permission again?

Thanks again!

0 Likes 0 ·
brendan avatar image brendan cmartin commented ·

One problem with Push is that it can disabled at the OS level, with zero notification being given to the application. So yes, one best practice is to occasionally re-request permission to send Push Notifications to the user. Be sure to a) keep track of when the user enters the game due to a click through a Push, so that you don't ever ask if it's obvious they do still have it on, and b) make this occasional/rare. "Needy" titles tend to irritate users. :)

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.