question

Kim Strasser avatar image
Kim Strasser asked

How frequently can I call RegisterForIOSPushNotificationAsync/AndroidDevicePushNotificationRegistrationAsync?

I use client API GetPlayerProfile to find out if the player has already enabled push notifications:

bool pushenabled = false;
var result = await PlayFabClientAPI.GetPlayerProfileAsync(new PlayFab.ClientModels.GetPlayerProfileRequest()
{
    PlayFabId = playfabid,
    ProfileConstraints = new PlayFab.ClientModels.PlayerProfileViewConstraints
    {
        ShowPushNotificationRegistrations = true
    }
});

if (result.Error != null)
{
}
else
{
    if (result.Result.PlayerProfile.PushNotificationRegistrations[0] != null)
        pushenabled = true;
}

After that, I call client API RegisterForIOSPushNotificationAsync/AndroidDevicePushNotificationRegistrationAsync if push notifications are not enabled.

Is it possible that the player has more than one device enabled for push notifications in result.Result.PlayerProfile.PushNotificationRegistrations?

What can I do if the player has already one iOS device enabled for push notifications and when the player uses a new device to login?

In this case, PushNotificationRegistrations[0] won't be null but the player won't get push notifications on his new device because I haven't called RegisterForIOSPushNotificationAsync/AndroidDevicePushNotificationRegistrationAsync on his new device because PushNotificationRegistrations[0] wasn't null.

Should I always call RegisterForIOSPushNotificationAsync/AndroidDevicePushNotificationRegistrationAsync when the player logs in, even if PushNotificationRegistrations[0] is not null?

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

·
Gosen Gao avatar image
Gosen Gao answered

Is it possible that the player has more than one device enabled for push notifications in result.Result.PlayerProfile.PushNotificationRegistrations?

There can be up to two values here, one for Android and one for iOS.

What can I do if the player has already one iOS device enabled for push notifications and when the player uses a new device to login?

You can store the player’s device info in the Player Data, once the player logs into the game with a new device, you can know by comparing this value and call the API to register new device.

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.

Kim Strasser avatar image Kim Strasser commented ·

Which device info should I store in Player Data? Do you mean the ios and Android NotificationEndpointARN?

var result = await PlayFabClientAPI.GetPlayerProfileAsync(new PlayFab.ClientModels.GetPlayerProfileRequest()
{
    PlayFabId = playfabid,
    ProfileConstraints = new PlayFab.ClientModels.PlayerProfileViewConstraints
    {
        ShowPushNotificationRegistrations = true
    }
});

for (int i = 0; i <= result.Result.PlayerProfile.PushNotificationRegistrations.Count - 1; i++)
{
    if (result.Result.PlayerProfile.PushNotificationRegistrations[i].Platform == PlayFab.ClientModels.PushNotificationPlatform.GoogleCloudMessaging)
        deviceandroid = result.Result.PlayerProfile.PushNotificationRegistrations[i].NotificationEndpointARN;
    else
    {
        if (result.Result.PlayerProfile.PushNotificationRegistrations[i].Platform == PlayFab.ClientModels.PushNotificationPlatform.ApplePushNotificationService)
            deviceios = result.Result.PlayerProfile.PushNotificationRegistrations[i].NotificationEndpointARN;
    }
}
0 Likes 0 ·
Gosen Gao avatar image Gosen Gao Kim Strasser commented ·

Device info means the device identifier for the user's device.

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.