Apple Push Notification not working with ad-hoc build not on development
Asked Answered
G

1

0

In development mode I can send push notification to devices, instead I can't in production, my setup is:

--> I have downloaded aps_production.cer certificates from provisioning portal and then double click the aps_production.cer installed keychain access finally get the private key from keychain access at that time it asked password i have given some password like "admin".

--> openssl pkcs12 -in CertificateName_pro.p12 -out CertificateName_pro.pem -nodes

--> apple server apn: 'gateway.push.apple.com' with 2195 port

-->The problem is that my rails application sends notifications and didn't receive any errors, but nothing arrived on devices.

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
           NSString *deviceTokenStr = [[[[deviceToken description]
                                          stringByReplacingOccurrencesOfString: @"<" withString: @""]
                                         stringByReplacingOccurrencesOfString: @">" withString: @""]
                                        stringByReplacingOccurrencesOfString: @" " withString: @""];

    }

simplepush.php

<?php

// Put your device token here (without spaces):
$deviceToken = 'deviceTokenStr';

// Put your private key's passphrase here:
$passphrase = 'admin';

// Put your alert message here:
$message = 'You have a new issue of admin!';

////////////////////////////////////////////////////////////////////////////////

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'CertificateName_pro.pem');
stream_context_set_option($ctx, 'ssl', 'admin', $passphrase);

// Open a connection to the APNS server
$fp = stream_socket_client(
                           'ssl://gateway.push.apple.com:2195', $err,
                           $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

// Create the payload body
$body['aps'] = array(
                     'alert' => $message,
                     'sound' => 'default',
                     'badge'
                     );

// Encode the payload as JSON
$payload = json_encode($body);

// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));

if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;

// Close the connection to the server
fclose($fp);

While run on terminal

Mac:test macmini$ php simplepush.php

Connected to APNS

Message successfully delivered

Giule answered 29/1, 2014 at 6:24 Comment(0)
A
1

Please be aware of the device token-ID,

which is different for the development && Production environment .

    - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
           NSString *deviceTokenStr = [[[[deviceToken description]
                                          stringByReplacingOccurrencesOfString: @"<" withString: @""]
                                         stringByReplacingOccurrencesOfString: @">" withString: @""]
                                        stringByReplacingOccurrencesOfString: @" " withString: @""];
           UIAlertView *alert= [[UIAlertView alloc]initWithTitle:deviceTokenStr message:Nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
    }
Amandaamandi answered 29/1, 2014 at 6:30 Comment(6)
how to get different device token id for the development && Production?Giule
this device token id for production then what about development?Giule
See, The token-id differs from the app which has setup with the nature of environment (dev OR production).Amandaamandi
If you are getting the token-id of the development. then the App is not at all built for the production environmentAmandaamandi
let us continue this discussion in chatAmandaamandi
Holy moly... i was crying because i couldnt figure out what was the problem.. Mr Kumar you just saved my life. I love you.. PLEASE BE AWARE OF THE DEVICE ID TOKEN WHICH IS DIFFERENT FOR THE DEVELOPMENT && PRODUCTION ENVIRONMENT... AWESOME..Corporate

© 2022 - 2024 — McMap. All rights reserved.