2016-04-26 23 views
0

私は電話ギャップを使用してiPhoneに通知を送信するために(push-plugin)を使用しています。私は私が正常にデバイストークンを取得していますPhoneGapのプロジェクト iOS、電話帳プッシュプラグイン( '通知')が発生していません

  • ため

    • 追加プッシュプラグインを行っている何

    • 私は正常にバックエンド
    • としてサーバー(PHP)を使用してAPNに 通知を送信しています。しかし、私はここで

    が私の作業コードである(PhoneGapの通知を受信できないよ - クライアント側):ここでは

    var push = PushNotification.init({ 
        ios: { 
         "alert": "true", 
         "badge": "true", 
         "sound": 'false' 
        } 
    }); 
    push.on('registration', function(data) { 
        console.log('your device token',data.registrationId); 
    }); 
    push.on('notification', function(data) { 
        console.log(('test'); 
        console.log(data.message); 
        console.log(data.title); 
        console.log(data.count); 
        console.log(data.sound); 
        console.log(data.image); 
        console.log(data.additionalData); 
    }); 
    push.on('error', function(e) { 
        console.log(e.message); 
    }); 
    

    私のSerで corodovaバージョン:6.1.2 のPhoneGap-プラグイン・プッシュバージョン:1.6.2 iPhone版:9.2

    QUSETIONなぜ私のコード(PHP)

    <?php 
    
        $deviceToken = '<my _device_token>'; 
    
    // Put your private key's passphrase here: 
    $passphrase = '<pass_phrase>'; 
    
    // Put your alert message here: 
    $message = "This is test notification"; 
    $url = "http://google.com"; 
    
    if (!$message || !$url) 
        exit('Example Usage: $php newspush.php \'Breaking News!\' \'https://google.com\'' . "\n"); 
    
    //////////////////////////////////////////////////////////////////////////////// 
    
    $ctx = stream_context_create(); 
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'abcdxyz.pem'); 
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); 
    
    // Open a connection to the APNS server 
    $fp = stream_socket_client(
        'ssl://gateway.sandbox.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', 
        'link_url' => $url, 
        'category' => "NEWS_CATEGORY", 
    ); 
    
    // 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); 
    

    ENVIRONMENT版モバイルデバイスは通知を受信できませんか?

  • 答えて

    0

    Iはpush.on('notification',function(){});

    push.finish()

    例内側に次の関数を追加することによって、上記の問題を解決:

    push.on('notification', function(data) 
    { 
         console.log(data.message); 
         console.log(data.title); 
    
         push.finish(function() 
         { 
          console.log('finish successfully called'); 
         });  
    });