question

Joel Auterson avatar image
Joel Auterson asked

Unable to set up iOS push notifications

Hi all,

I've been unable to set up push notifications on iOS using the instructions on this doc. Attempting to use the request generator on the page gives an "unable to locate private key" error with my PEM file.

Attempting to use the API with a self-created request gives me the error "Invalid parameter: PlatformPrincipal not valid.". I tried using newlines, replacing the newlines with '\n', and having a single long string with no newlines, all to no avail; the error remains the same.

I was able to set up Android/GCM notifications using this API. I could always use Firebase on iOS, but it seems wasteful to add a load of extra dependencies when native notifications would serve my needs. Can anyone help?

Thanks

Joel

Push Notificationsdocumentation
10 |1200

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

me-2 avatar image
me-2 answered

This is a lot more difficult than it should be. I tried to upload it through the web admin and it didn't work at all (error documented in a couple of other forum posts). Then I tried the script and received the error: "Invalid parameter: PlatformPrincipal not valid." Finally, I got it working sending the request directly using Postman. I just copied and pasted the key portion without replacing anything. Here are screenshots of the request. I have partially covered the keys so you understand what I mean:


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.

Joel Auterson avatar image Joel Auterson commented ·

Yep, looks like you ran into a similar issue. Unsure if PF aren't able to reproduce the problem on their end or if they simply don't care.

I'd honestly recommend bypassing PlayFab and using Firebase directly; I didn't have any issues doing this, and you need a Firebase setup in order to use Android notifications anyway.

0 Likes 0 ·
Citrus Yan avatar image
Citrus Yan answered

Can you provide some key steps for us to reproduce your issue? Also, screenshots will be a good a help too, thanks.

By the way, I found this thread that may relate to your issue some way, you can check it out.

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

Joel Auterson avatar image Joel Auterson commented ·

Hi Citrus - I'm not sure what repro steps or screenshots I would provide beyond what I already have. You can reproduce the issue yourself by following the instructions on the page I linked and then pasting the contents of your PEM file into the JSON generator on the same page.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Joel Auterson commented ·
0 Likes 0 ·
Joel Auterson avatar image Joel Auterson Seth Du ♦ commented ·

Hi @SethDu - unfortunately this format does not work with the generator either.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Joel Auterson commented ·

Have you tried to implement/set up it directly on your Game Manager instead of using API? These 2 methods are same because you won't change it frequently.

I am not sure if there is any issues on the web tool, but the request for Title-Wide Data Management - Setup Push Notification should be like:

{
  "Name": "My Game",
  "Platform": "APNS_SANDBOX",
  "Key": "MyKey123",
  "Credential": "MyCredentialsXYZ",
  "OverwriteOldARN": false
}

Be aware that there are only three options for property Platform and they are all upper case string, you may refer to: https://docs.microsoft.com/en-us/rest/api/playfab/admin/title-wide-data-management/setuppushnotification?view=playfab-rest#pushsetupplatform

You can also paste your sample request in this thread (please hide sensitive information like keys), we just need to check the format.

0 Likes 0 ·
Joel Auterson avatar image Joel Auterson Seth Du ♦ commented ·

Hi @SethDu - I can confirm I'm using this format. Trying to use the file upload on the game manager gives me this error:

  • Invalid parameter: Name Reason: An application with the same name but different properties already exists

I was able to get around this on Android via the API.

0 Likes 0 ·
Show more comments
Joel Auterson avatar image
Joel Auterson answered

In the end I worked around this by changing my game title in the web UI, uploading the file, and then changing it back - so clearly my certificate was correct.

I am going to leave this question open until someone from PlayFab addresses the fact that the aforementioned request generator is broken, and/or that the API documentation is either incorrect or missing something.

Thanks to those who helped so far!

10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

@joelautersonHi Joel, I think the request generator is alright, the js code could give us some info:

<script>var button=document.getElementById("ppg-convert"),
    output=document.getElementById("ppg-output");
    
button.addEventListener("click", function(){
    var json = { };
    var pem = document.getElementById("ppg-pem").value;
    var platform = document.getElementById("ppg-platform").value;
    json['Platform'] = platform;
    json['Name'] = document.getElementById("ppg-name").value;
    json['OverwriteOldARN'] = document.getElementById("ppg-overwriteArn").checked;
    if(platform === 'GCM'){
        json['Credential'] = pem;
    } else {
        var certificateRegex = /-----BEGIN CERTIFICATE-----[\s\S]+-----END CERTIFICATE-----/g;
        var keyRegex = /-----BEGIN RSA PRIVATE KEY-----[\s\S]+-----END RSA PRIVATE KEY-----/g;
        var certificate = certificateRegex.exec(pem);
        var key = keyRegex.exec(pem);
        
        if(!certificate || certificate.length == 0){
            output.textContent = "Could not locate PEM certificate!"
        }
        if(!key || key.length == 0){
            output.textContent = "Could not locate Private Key!"
        }
        certificate = certificate[0]; //flatten;
        key = key[0]; //flatten
        
        json['Credential'] = key;
        json['Key'] = certificate;
    }
    output.textContent=JSON.stringify(json,null,2);
});
</script></p>

I tested typying "/-----BEGIN CERTIFICATE-----xxxxxxx-----END CERTIFICATE-----/ -----BEGIN RSA PRIVATE KEY-----xxxxxxxxxxxxxx-----END RSA PRIVATE KEY-----" in the PEM Certificate / API Key text area, and get the following output:

Therefore, there was probably some formatting issue with your PEM Certificate?


10 |1200

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

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.