23

My organisation maintains multiple applications and there's a confusion about how the APNs keys are supposed to be used. We are using firebase to send push notifications.

So far we have two apple keys for two different applications. But cannot create a third key with APNs activated. Apple key APNs error

This question indicates that we're supposed to use the same key for all applications.

My questions are:

If we only can create two keys for one organisation is one supposed to be used for production and one for testing/development?

If we use the same keys for multiple unrelated application (unrelated except that the apps are all created by the same organisation) what stops cloud messages from being pushed to the wrong application. Is it related to identifiers for apps? Are we supposed to create a convention to circumvent the problem of sending messages to the wrong app? ( I don't actually think this is a very valid option. It feels very wrong.)

For example:

  • using topics with a prefix for each app?
  • create device groups, one for each app?

I've asked this question here as well: https://forums.developer.apple.com/message/415911#415911

Community
  • 1
  • 1
Tejpbit
  • 450
  • 1
  • 4
  • 13

1 Answers1

38

The key is used to authenticate to the service. It identifies your organisation to the service.

The reason you can have two keys is so that you can create a new one before revoking the old one if the key is compromised.

When an app registers for remote notifications you receive an identifier that is unique for that app on that device. If you have multiple apps on that device each will get a different identifier.

When you send a push notification the identifier ensures that it gets to the right app on the right device.

You need to ensure that you store the identifier against the right app on your backend (or you may have different backends for different apps).

Joshua
  • 3,055
  • 3
  • 22
  • 37
Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • 2
    Thank you for your answer! What about FCM topics: https://firebase.google.com/docs/cloud-messaging/android/topic-messaging ? If I install two different apps with the same key on two devices. How do firebase and apple distinguish between the two different apps? Is it when one creates two applications on firebase and generate two different GoogleService-Info.plist files? – Tejpbit May 12 '20 at 09:30
  • 2
    If you use FCM then you need to create a different firebase app for each iOS app, and this is reflected in the GoogleService file as you mentioned. Then the application push notification registration is recorded against the correct application in the Firebase backend – Paulw11 May 12 '20 at 09:31
  • 1
    Alright. I see. Just wanted to make sure we don't push random notifications between different apps. Thank you for your help! – Tejpbit May 12 '20 at 09:38
  • If there are 2 keys, does single app will be signed using both keys? – Hayi Nukman Nov 19 '21 at 03:55
  • What if you have 2 or more firebase projects for the same app, e.g. for production/staging environments, do you need multiple APN auth keys for each firebase project? – dimib Apr 25 '22 at 11:08
  • You would have different iOS apps with different bundle ids for the different firebase projects and each would store its own remote notification identifiers – Paulw11 Apr 25 '22 at 11:27
  • Actually no, I could check and verify that it is legit to use the same APN auth key for the same app ID on different Firebase projects (dev/staging/production), so this is great news – dimib Apr 27 '22 at 08:24
  • Can I use a single key for the bundle Ids present two different Teams in my apple dev account? – Siddhant maurya Sep 29 '22 at 08:34