5

I'm trying to set up push notifications through Amazon SNS in Unity.

I have the Android side of things working perfectly but we're having issues with iOS. I am able to get the device to register to a Apple Production SNS application and subscribe to a topic but as soon as I attempt to send a notification the endpoints "Enabled" status becomes "False".

I read that this could be due to the certificate being set as Production although we followed the instructions on creating a Development certificate, when I try uploading the .p12 file to create an Apple Development platform in SNS it always gives an error saying:

"You provided a certificate of type iOS Production"

We have tried multiple times to download the development certificate and tried rebuilding the app with a new bundle ID and new app on the Apple development site without touching the production button but it always ends up being a production certificate after exporting the .p12 from KeyChain...

Also, every .p12 we have created had the exact private key and certificate as the last.

What could be going wrong?

Obi-Dan
  • 113
  • 1
  • 8
  • 5
    Try to export the push certificate without including the private key. This may work, I've encountered similar issue before, and solved it in this way. The problem is that the private key is used for signing both the development and production push certificates. – utogaria Aug 07 '15 at 18:19
  • Ok thanks, I will give that a go now :) – Obi-Dan Aug 10 '15 at 08:54
  • Cool, let me know if it doesn't help. – utogaria Aug 10 '15 at 08:56
  • 1
    Thanks! That worked perfectly. – Obi-Dan Aug 10 '15 at 09:04
  • Well, it worked for creation of the Sandbox App through SNS but now the device is saying "No valid 'aps-environment' entitlement string found" – Obi-Dan Aug 10 '15 at 10:22
  • 1
    I've found some questions similar to "No valid 'maps-environment' entitlement string found" in stackoverflow. There could be answers to this question. I strongly recommend you to have try and see if they help. Apple's certificate/signing/provisioning is quite complicated compared to other platforms, so, just be careful when you configure them on your app. Basically, you need to make sure that, for each environment, debug/release (aka, development/production), the push certificate, provisioning profile, code signing are consistent in order for the push to work. – utogaria Aug 10 '15 at 11:08
  • 1
    If you can't fix the problem after trying all the solutions in stackoverflow, you can come back to me, I'll figure something else. – utogaria Aug 10 '15 at 11:09
  • Yep, I figured that part out - Build settings not targeting the right entitlements... Now I can register with SNS, subscribe to a topic, the endpoint stays as Enabled = true but sending a notification through a topic or directly to the endpoint does nothing. In Android I had to set up my own broadcast receiver for this last part, do I need something similar for iOS or should Unity be doing this automatically? – Obi-Dan Aug 10 '15 at 13:49
  • I'm afraid I don't know much about Unity. What's the remaining problem? Could you explain the problem more clearly? – utogaria Aug 10 '15 at 14:31
  • I'm using AWS SDK in Unity to set up the SNS endpoint and subscription but I can't find any way of actually receiving the messages through a background service or some kind of callback procedure. On the Android build I had to manually add a new Java class for a broadcast receiver which would pick up the message and let me parse it/act on it. Now I can't figure out how to achieve the same thing on iOS although the Xcode debug log isn't showing any kind of incoming messages like Android did so I don't even know if the messages are getting sent properly... – Obi-Dan Aug 10 '15 at 14:43
  • So maybe there's some class I can set up in Xcode to achieve something similar. [I found this](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDistributedNotificationCenter_Class/index.html#//apple_ref/occ/cl/NSDistributedNotificationCenter) but I don't think it's what I'm looking for? – Obi-Dan Aug 10 '15 at 14:50
  • I just tried another message through my PHP page just to make sure it was still working on the Android devices when it popped up out of nowhere on the iPad. Seem to have it sussed finally, cheers for all the help! :) – Obi-Dan Aug 10 '15 at 15:02
  • NSDistributedNotificationCenter doesn't seem to be the answer, since it's only available on OS X platform. I don't know much about exact what you want to achieve, but I get a feeling that the server is trying to actively notify your client app via APN service, (again, I'm just speculating here) if this is the case, you should check if you allow app to be waken up by push notification, since iOS push notification (content-available type) can launch the app to background and allow the app to execute some code. I'm not sure if that's what you're looking for. – utogaria Aug 10 '15 at 15:31
  • Thanks Guys... Very Useful :-) – Hernan Arber May 08 '16 at 15:17

2 Answers2

13

This Worked for Me:

1 - Download the Certificate from Apple (APNS Certificate for Development or Production)

2 - Double click on your Certificate to open it in your KeyChain

3 - Select it, Right-Click on it and press EXPORT "Cer" *** DO NOT SELECT IT TOGETHER WITH YOUR PRIVATE KEY, Select it By ITSELF!

4 - Name your new p12 and Upload this to SNS in the Setup Stage

DONE, this will work!

---> Its weird that Amazon's SNS requires a NON-Signed .p12 instead of the Combined .p12 (including private key) like other platforms, but... Go Discuss with Amazon...

Hernan Arber
  • 1,626
  • 3
  • 22
  • 35
1

This worked for me;

Follow the steps in this guide;

http://docs.aws.amazon.com/sns/latest/dg/mobile-push-apns.html

Now in SNS when creating DO NOT upload the p12.

Open up the files generated in step 2 & 3 in a text editor.

Copy the certificate from the .pem generated in step 2 into the certificate text area.

Copy the private key from the .pem generated in step 3 to the private key text area.

It should create. My guess is that some old certificate was being tagged along in my .p12 file.

David
  • 3,285
  • 1
  • 37
  • 54
Brian F
  • 1,620
  • 1
  • 19
  • 23