81

I have tested push notifications as a developer account and it worked, But when i tried to put it on TestFlight for the testers to test it, it didn't show a push notification but the data is correctly received, So is there a kind of certificate that i need to generate for TestFlight?

Iman
  • 1,097
  • 2
  • 11
  • 19
  • 3
    Use production certificate for TestFlight, because its a distribution build, and use ssl://gateway.push.apple.com:2195 instead of sandbox URL to send the notification – Tarun Seera Apr 05 '16 at 11:07

9 Answers9

84

But when i tried to put it on TestFlight for the testers to test it, it didn't show a push notification but the data is correctly received.

That sentence is confusing. If you didn't get the push notification, what data is correctly received?

Anyway, if I recall correctly, for TestFlight you are using an AdHoc provisioning profile, which works with the production push environment. Therefore you'll need a production push certificate in order to push to devices that installed the app via TestFlight. In addition, don't forget that development device tokens are different than production device tokens, so make sure you are using the correct tokens.

Eran
  • 387,369
  • 54
  • 702
  • 768
  • 2
    i haven't seen anything about production device tokens in the docs - could you specify this a bit? – Bergrebell Oct 17 '15 at 15:51
  • 7
    @PeterPiper `If the token came from the sandbox environment, such as when you are testing a development build in house, you can't send it to the production push service. Each push environment will issue a different token for the same device or computer. If you do send a device token to the wrong environment, the push service will see that as an invalid token and discard the notification.` taken from [here](https://developer.apple.com/library/ios/technotes/tn2265/_index.html). – Eran Oct 17 '15 at 15:55
  • 1
    Dear @Eran, do you have any tutorial to show how to create production certificate ? – user3751548 Feb 09 '17 at 09:09
  • Would that apply also for Notifications for the GameKit? – Apostolos Jun 26 '17 at 22:29
  • 1
    @tallis I don't know. – Eran Jun 27 '17 at 05:49
43
  1. You need to use production certificate for testflight build.
  2. Also need to remove sanbox (sandbox mode) from push notification url in push sending script.
pableiros
  • 14,932
  • 12
  • 99
  • 105
Sandeep
  • 766
  • 5
  • 16
13

If you use Firebase, you have to add in:

  • TestFlight:

    -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
        [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeSandbox]; 
    }
    
  • Production:

    -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
        [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeProd]; 
    }
    
pableiros
  • 14,932
  • 12
  • 99
  • 105
delarcomarta
  • 263
  • 3
  • 9
  • 1
    This might be a very stupid question, but what happens if you do both? – Gábor Angyal Jan 26 '17 at 07:26
  • 3
    @GáborAngyal - Not clear what happens. Interesting is this sentence "If the token type is set to FIRInstanceIDAPNSTokenTypeUnknown InstanceID will read the provisioning profile to find out the token type." from [Firebase API FIRInstanceID setAPNSToken:type:](https://firebase.google.com/docs/reference/ios/firebaseinstanceid/api/reference/Classes/FIRInstanceID#/c:objc(cs)FIRInstanceID(im)setAPNSToken:type:). Logically, that says **everyone** could simply do `type: FIRInstanceIDAPNSTokenTypeUnknown`, so that we don't have to remember to change this. Haven't tried this myself... – ToolmakerSteve Feb 14 '17 at 23:59
  • 1
    I tried using the `FIRInstanceIDAPNSTokenTypeUnknown` valuef or the type argument and can confirm that I was able to receive push notification on testflight builds – Tope Apr 15 '17 at 18:13
  • 2
    with Firebase 4.0 new Swift syntax it is now Messaging.messaging().setAPNSToken(deviceToken, type: .unknown) – dmathewwws Sep 28 '17 at 17:59
  • what is the file I need to add this function from answer? – alexandre9865 Apr 06 '21 at 11:16
  • 1
    @alexandre9865 - this is AppDelegate.m – fullStackChris Jun 22 '21 at 13:26
6

For TestFlight, use

  1. Production certificate
  2. "gateway.push.apple.com" at the server(back end job)
Md Rais
  • 972
  • 1
  • 12
  • 21
5

if you used GCM. In Development:-

_registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken,
                             kGGLInstanceIDAPNSServerTypeSandboxOption:@YES};

In Distribution:-

_registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken,
                             kGGLInstanceIDAPNSServerTypeSandboxOption:@NO};
Ahmed Abdallah
  • 2,338
  • 1
  • 19
  • 30
2

We need two certificates for sending notifications, one for development and one for production. In my case I'm using PushSharp solution to send notification .

This is for development:

var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, "development.p12", "password");
var broker = new ApnsServiceBroker(config);

This is for Production:

var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, "production.p12", "password");
var broker = new ApnsServiceBroker(config);
Jacopo Penzo
  • 2,168
  • 2
  • 24
  • 29
Loki
  • 1,180
  • 9
  • 13
2

For someone uses Python apns (https://github.com/djacobs/PyAPNs):

When you create APNS object such apns = APNs(cert_file="cert.pem", key_file="key.pem"). You need to add one more parameter use_sandbox. It will be apns = APNs(use_sandbox=False, cert_file="cert.pem", key_file="key.pem").

Happy coding.

Luat Vu Dinh
  • 460
  • 6
  • 10
0

Please ensure that you have set FirebaseAppDelegateProxyEnabled to YES in info.plist file.

AnupamChugh
  • 1,779
  • 1
  • 25
  • 36
0

For Firebase try this:

#if DEBUG
    Messaging.messaging().setAPNSToken(apnsToken, type: .sandbox)
#else
    Messaging.messaging().setAPNSToken(apnsToken, type: .prod)
#endif
Andrey M.
  • 3,021
  • 29
  • 42