Why push notifications is not working on testflight?
Asked Answered
S

9

82

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?

Scilla answered 4/6, 2014 at 17:54 Comment(1)
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 notificationElsewhere
P
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.

Peduncle answered 4/6, 2014 at 18:47 Comment(5)
i haven't seen anything about production device tokens in the docs - could you specify this a bit?Lacroix
@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.Peduncle
Dear @Eran, do you have any tutorial to show how to create production certificate ?Laue
Would that apply also for Notifications for the GameKit?Ube
@tallis I don't know.Peduncle
L
44
  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.
Lorrimor answered 10/12, 2014 at 18:23 Comment(2)
Testing:gateway.sandbox.push.apple.com Production:gateway.push.apple.comAgeold
Ok... but then how can we control sending test notification only to our test clients if they use the same certificates?Hamman
P
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]; 
    }
    
Purulence answered 13/9, 2016 at 12:0 Comment(6)
This might be a very stupid question, but what happens if you do both?Pulp
@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:. 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...Vociferant
I tried using the FIRInstanceIDAPNSTokenTypeUnknown valuef or the type argument and can confirm that I was able to receive push notification on testflight buildsEviscerate
with Firebase 4.0 new Swift syntax it is now Messaging.messaging().setAPNSToken(deviceToken, type: .unknown)Maniemanifest
what is the file I need to add this function from answer?Vouge
@Vouge - this is AppDelegate.mHamman
P
6

For TestFlight, use

  1. Production certificate
  2. "gateway.push.apple.com" at the server(back end job)
Palaeolithic answered 20/2, 2018 at 17:25 Comment(2)
Where can I change this config of server?Vouge
Hi Alexandre, I am not sure exactly where the backend developer declares the gateway coz Im not a backend developer. But I know that at some point we have to write it.Palaeolithic
A
5

if you used GCM. In Development:-

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

In Distribution:-

_registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken,
                             kGGLInstanceIDAPNSServerTypeSandboxOption:@NO};
Alexia answered 5/4, 2016 at 10:59 Comment(0)
P
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);
Pizzicato answered 2/8, 2017 at 8:21 Comment(0)
P
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.

Pearliepearline answered 23/4, 2019 at 9:28 Comment(0)
C
0

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

Cineaste answered 15/8, 2019 at 6:52 Comment(0)
C
0

For Firebase try this:

#if DEBUG
    Messaging.messaging().setAPNSToken(apnsToken, type: .sandbox)
#else
    Messaging.messaging().setAPNSToken(apnsToken, type: .prod)
#endif
Caseous answered 30/7, 2020 at 3:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.