Push notification not receiving on iphone

前端 未结 5 1361
梦谈多话
梦谈多话 2020-12-15 11:03

I am using this tutorial to learn push notification.



        
相关标签:
5条回答
  • 2020-12-15 11:14

    Use UrbanAirShip. In my opinion it's the best server side solution since it includes Push-alike notifications for Android (C2DM) and Blakberry too.

    Try finding differences between these to files and understand them. Might be a solution to your problem. Here's my code:

    <?php
    
    $message = 'Hello'; // $_GET or $_POST
    $badge = 3; // int
    $sound = 'default'; // string - sound name
    $development = true; // boolean
    
    $payload = array();
    $payload['aps'] = array('alert' => $message, 'badge' => intval($badge), 'sound' =>    $sound);
    $payload = json_encode($payload);
    
    $apns_url = NULL; // Set Later
    $apns_cert = NULL; // Set Later
    $apns_port = 2195;
    
    if($development)
    {
        $apns_url = 'gateway.sandbox.push.apple.com';
        $apns_cert = '/path/apns.pem'; // relative address to an App Specific Certificate     file 
    }
    else
    {
        $apns_url = 'gateway.push.apple.com';
        $apns_cert = '/path/cert-prod.pem';
    }
    
    $stream_context = stream_context_create();
    stream_context_set_option($stream_context, 'ssl','local_cert',$apns_cert);
    
    $apns = stream_socket_client('ssl://'.$apns_url.':'.$apns_port,$error,$error_string,2,STREAM_CLIENT    _CONNECT,$stream_context);
    
    //  You will need to put your device tokens into the $device_tokens array yourself
    $device_tokens = array(); // tokens!!!
    
    foreach($device_tokens as $device_token)
    {
        $apns_message = chr(0).chr(0).chr(32).pack('H*',str_replace('    ','',$device_token)).chr(0).chr(strlen($payload)).$payload;
        fwrite($apns, $apns_message);
    }
    
    @socket_close($apns);
    @fclose($apns);
    ?>
    
    0 讨论(0)
  • 2020-12-15 11:20

    Implement the feedback service on server side and also check on server side that within how much duration all the device token are send to APNS. From feedback service atleast u will come to know that how much devices had received ur notification. If all the device token are send one by one to the APNs and the APNs does'nt send any list through feedback service then u cannot handle the duration to receive notification on devices.

    0 讨论(0)
  • 2020-12-15 11:23

    Check your push notification certificate. is certificate was associate with any private key?

    If no then please recreate push notification certificate with appropriate private key which are generated from your key chain.

    Please take a look at the below Tutorial:

    Apple Push Notification Tutorial:

    thanks,

    MinuMaster

    0 讨论(0)
  • 2020-12-15 11:27

    First make sure that you're using:

    • The application is compiled with debug/release provision
    • your keychain has the devlopment/production push notification certificate

    then use the following code (been tested both dev & production)

    <?php
    // Comment these lines in production mode
    ini_set('display_errors','on');
    error_reporting(E_ALL);
    
    
    // Apns config
    
    // true - use apns in production mode
    // false - use apns in dev mode
    define("PRODUCTION_MODE",false);
    
    $serverId = 1;
    $serverName = 'my-server-domain.com';
    
    if(PRODUCTION_MODE) {
    $apnsHost = 'gateway.sandbox.push.apple.com';
    } else {
    $apnsHost = 'gateway.push.apple.com';
    }
    
    $apnsPort = 2195;
    if(PRODUCTION_MODE) {
    // Use a development push certificate 
    $apnsCert = $_SERVER['DOCUMENT_ROOT'].'/apns/apns-dominos-development.pem';
    } else {
    // Use a production push certificate 
    $apnsCert = $_SERVER['DOCUMENT_ROOT'].'/apns/apns-dominos-production.pem';
    }
    
    
    // --- Sending push notification ---
    
    // Insert your device token here 
    $device_token = "<dc6127d8 dc6127d8 dc6127d8 dc6127d8 dc6127d8 dc6127d8 dc6127d8    dc6127d8>"; // Some Device Token
    
    
    // Notification content
    
    $payload = array();
    
    //Basic message
    $payload['aps'] = array(
    'alert' => 'testing 1,2,3..', 
    'badge' => 1, 
    'sound' => 'default',
    );
    $payload['server'] = array(
    'serverId' => $serverId,
     'name' => $serverName
    );
    // Add some custom data to notification
    $payload['data'] = array(
    'foo' => "bar"
    );
    $payload = json_encode($payload);
    
    $streamContext = stream_context_create();
    stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
    stream_context_set_option($streamContext, 'ssl', 'passphrase', "");
    
    
    $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error,      $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
    
    
    $deviceToken = str_replace(" ","",substr($device_token,1,-1));
    echo $deviceToken;
    $apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '',      $deviceToken)) . chr(0) . chr(mb_strlen($payload)) . $payload;
    fwrite($apns, $apnsMessage);
    
    
    //socket_close($apns);
    fclose($apns);
    
    ?>
    
    0 讨论(0)
  • 2020-12-15 11:29

    Okay i finally got my Problem. The problem is not in code actually the problem is in Wrong DNS Value set in my iphone. Iphone automatically place ip of my router for DNS field. Now i give the DNS value of my service provider then it works fine. Now I am receiving Push messages As soon as i sent them.

    I Hope it helps others.

    0 讨论(0)
提交回复
热议问题