2016-04-26 2 views
0

Ich benutze(), um Benachrichtigungen an iPhone mit Telefon Gap zu senden.iOS, Telefon Lücke Push-Plugin auf ("Benachrichtigung") nicht ausgelöst

Was ich

  • hinzugefügt Push-Plugin für PhoneGap Projekt
  • Ich erhalte Gerät Token erfolgreich getan haben.
  • Ich Benachrichtigungen an APN erfolgreich Senden mit Server (PHP) als Backend
  • Aber ich bin nicht in der Lage, um Benachrichtigungen zu erhalten

Hier ist mein Arbeitscode (PhoneGap - Client-Seite):

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); 
}); 

Hier ist mein Ser ver-Code (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); 

UMWELT: corodova Version: 6.1.2 phonegap-Plugin-Push-Version: 1.6.2 iPhone-Version: 9,2

qusetion Warum Mobilgerät kann keine Benachrichtigungen empfangen?

Antwort

0

gelöst I das obige Problem durch folgende Funktion innerhalb push.on('notification',function(){});

push.finish()

Beispiel Anfügen:

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

     push.finish(function() 
     { 
      console.log('finish successfully called'); 
     });  
}); 
Verwandte Themen