Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi !

I want to send a push notification message to our iOS mobile clients using APNs Server, but i get the response "invalid device token" back from the APNs.

What's going wrong ?

I have the valid certifications and p12 files, i used the device token i received to my iphone.

Here some server code:

What I have tried:

string certPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "nlcprod.p12");
                bool exist = File.Exists(certPath);
                var cert = File.ReadAllBytes(certPath);
                var appleSettings = new PushSharp.Apple.ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, cert, "");
                var pushBroker = new PushSharp.Apple.ApnsServiceBroker(appleSettings);

                pushBroker.OnNotificationFailed += (notification, aggregateEx) =>
                {
                    string strEx = aggregateEx.ToString();
                };
                pushBroker.OnNotificationSucceeded += PushBroker_OnNotificationSucceeded;
               // PushSharp.Apple.ApnsServiceConnection connection = new ApnsServiceConnection(appleSettings);

                JObject jObject = JObject.Parse(str);
                ApnsNotification apnsNotification = new ApnsNotification
                {
                    DeviceToken = "97056623 0caedd1c 0c96a264 f16cbf57 d9fa7236 08046144 6160ee95 94616364",
                    Payload = JObject.Parse("{\"aps\":{\"badge\":1,\"sound\":\"oven.caf\",\"alert\":\"testmessage\"}}")
                };

                //connection.Send(apnsNotification);
                pushBroker.Start();
                pushBroker.QueueNotification(apnsNotification);
Posted
Updated 3-Jul-18 23:55pm

1 solution

There's two things I notice:

1. The device token shouldn't have spaces. Try remove them.

2. Based on the name of your certificates, you are using a production certificate. This requires a production device token, which you will get when your app is built with an Ad-Hoc or AppStore provisioning profile. Are you using a Development profile?

If not, can you share the code to retrieve the device token?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900