0

I prepared an iphone application that gets push notification messages. I can send push message using with 2195 port , gateway.sandbox.push.apple.com and local p12 file

My application in appstore, now i'm using gateway.push.apple.com and distribution p12 file, but messages cannot reach to real application (in appstore)

Device ids are different in local and prod version, I know this so i'm trying to send new device id from .net

Same codes works in local and i can send messages but when i send push message to real application, no message reach to iphone with the same codes. I have no error during this period.

What can i do?

my c# code like below. How can i solve my problem? There is no error but message cannot reach to devices with distribution cert.

int port = 2195;

    String hostname = "gateway.push.apple.com";

    String certificatePath = HttpContext.Current.Server.MapPath("distribution.p12");


    X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "xxx", X509KeyStorageFlags.MachineKeySet |
    X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

    X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);
    TcpClient client = new TcpClient(hostname, port);
    SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
    try
    {
        sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Tls, true);
    }
    catch (Exception e)
    {
        throw (e);
        client.Close();
        return;
    }
    MemoryStream memoryStream = new MemoryStream();
    BinaryWriter writer = new BinaryWriter(memoryStream);
    writer.Write((byte)0); 
    writer.Write((byte)0);  //The first byte of the deviceId length (big-endian first byte)
    writer.Write((byte)32); //The deviceId length (big-endian second byte)
    //String deviceID = "f1430c99 910d292d 2f756294 f2f6b348 153bc215 d5404447 16b294eb fdb9496c";
    writer.Write(HexStringToByteArray(deviceID.ToUpper()));
    String payload = "{\"aps\":{\"alert\":\"" + Mesaj + "\",\"badge\":0,\"sound\":\"default\"}}";
    writer.Write((byte)0);
    writer.Write((byte)payload.Length);
    byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
    writer.Write(b1);
    writer.Flush();
    byte[] array = memoryStream.ToArray();
    sslStream.Write(array);
    sslStream.Flush();
    client.Close();
cdsoft
  • 621
  • 2
  • 8
  • 15
  • This is very important for me, please help me :( – cdsoft Apr 02 '14 at 08:47
  • after enabled your notification process. You must re-upload the app to itunes store. Include the .pem file into to the project folder before build. – Senthilkumar Apr 02 '14 at 08:48
  • My project doesn't include pem file, Is my problem related with pem file? which folder should i add this file? – cdsoft Apr 02 '14 at 09:49
  • my problem still continue – cdsoft Apr 02 '14 at 11:47
  • Now can you able to test with your's developer devices?. If notification get properly means you may update your app in itunes store. – Senthilkumar Apr 02 '14 at 12:24
  • I can get push message with developer certificate using with p12 file (i didn't use pem file) Code is the same in local and appstore, only i changed address from gateway.sandbox.push.apple.com to gateway.push.apple.com and i changed from developer.p12 file to distributred.p12 file, ofcourse device ids different. – cdsoft Apr 02 '14 at 12:36
  • I'm about to lose my hope :( – cdsoft Apr 03 '14 at 10:36
  • Is there anyone who can help? – cdsoft Apr 07 '14 at 07:49

1 Answers1

0

After enabled your push notification in your profile appid.

Then only you can able to get device token from the running device. Based on the device token you may send notification.

development process : gateway.sandbox.push.apple.com port 2195.

distribution process : gateway.push.apple.com port 2195.

refer from this links: https://stackoverflow.com/a/10045210/510814

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html

Community
  • 1
  • 1
Senthilkumar
  • 2,471
  • 4
  • 30
  • 50
  • Push notification enable both developer and distribution I used new device id from running device I used gateway.push.apple.com port 2195 I can send notification with developer certificate but I can't send messages to downloaded application from appstore I have no error in .net I have problem still – cdsoft Apr 02 '14 at 07:29
  • you must use device token to send notification. To get device token - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { } – Senthilkumar Apr 02 '14 at 07:44
  • I used device token, i get device token with the same code above already – cdsoft Apr 02 '14 at 08:29