Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • Bugs /
avatar image
Question by Takuya Nakajo · Nov 09, 2020 at 10:07 AM ·

The first of AdvancedPlatformDelivery always runs

Hello.

I'm writing SendPushNotification as follows.

[FunctionName("SendPushNotification")]
public static async Task<dynamic> SendPushNotification(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
{
    string body = await req.ReadAsStringAsync();
    var context = JsonConvert.DeserializeObject<PlayerPlayStreamFunctionExecutionContext<dynamic>>(body);
    string playFabId = context.PlayerProfile.PlayerId;

    var serverApi = GetServerInstance(context.TitleAuthenticationContext);
    var result = await serverApi.SendPushNotificationAsync(new SendPushNotificationRequest
    {
        Recipient = playFabId,
        AdvancedPlatformDelivery = new List<AdvancedPushPlatformMsg>
        {
            new AdvancedPushPlatformMsg
            {
                Json = "{\"alert\":{\"title\":\"プッシュ通知タイトル\",\"body\":\"プッシュ通知メッセージ\",\"badge\":1,\"sound\":\"default\"}",
                Platform = PushNotificationPlatform.ApplePushNotificationService
            },
            new AdvancedPushPlatformMsg
            {
                Json = "{\"title\":\"プッシュ通知タイトル\",\"body\":\"プッシュ通知メッセージ\",\"sound\":\"default\"}",
                Platform = PushNotificationPlatform.GoogleCloudMessaging
            },
        }
    });

    return new
    {
        error = PlayFabSimpleJson.SerializeObject(result.Error),
        result = PlayFabSimpleJson.SerializeObject(result.Result)
    };
}

private static PlayFabServerInstanceAPI GetServerInstance(TitleAuthenticationContext titleAuthenticationContext)
{
    var apiSettings = new PlayFabApiSettings
    {
        TitleId = titleAuthenticationContext.Id,
        DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process),
    };

    return new PlayFabServerInstanceAPI(apiSettings);
}

I have specified two in AdvancedPlatformDelivery, iOS and Android, but apparently the first one is being used in a fixed way.

This means that when I put iOS and Android in the list in order, when I run Android push notifications, the iOS one will be called and I will get an error.

"error": "{\"HttpCode\":400,\"HttpStatus\":\"BadRequest\",\"Error\":1071,\"ErrorMessage\":\"Invalid JSON in request\",\"ErrorDetails\":{\"ValidationError\":[\"Unexpected end when deserializing object. Path 'alert', line 1, position 80.\"]},\"RequestId\":\"Failed to Enumerate RequestId. Exception message: Enumeration has not started. Call MoveNext.\"}",

Is this a bug?

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Jay Zuo · Nov 10, 2020 at 09:17 AM

As the error message said, you are providing a wrong JSON string in your AdvancedPushPlatformMsg. If you unescape your JSON string

{\"alert\":{\"title\":\"プッシュ通知タイトル\",\"body\":\"プッシュ通知メッセージ\",\"badge\":1,\"sound\":\"default\"}

You will find it misses a "}".

{"alert":{"title":"プッシュ通知タイトル","body":"プッシュ通知メッセージ","badge":1,"sound":"default"}

You can add the "}" and use the following string to see if it works:

{\"alert\":{\"title\":\"プッシュ通知タイトル\",\"body\":\"プッシュ通知メッセージ\"},\"badge\":1,\"sound\":\"default\"}
Comment
Takuya Nakajo

People who like this

1 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Takuya Nakajo · Nov 10, 2020 at 10:00 AM 0
Share

I missed it. I'm sorry. It worked well.Thank you.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges