2015-07-11 165 views
0

推送通知在iOS 8中未收到。推送通知iOS 8未接收

任何一個可以告訴我這可能是服務器端的問題。它顯示推送通知發送成功,但不能在設備上接收。

請參閱PHP和Xcode是這樣的嗎?

<?php  
// Put your device token here (without spaces): 
$deviceToken = '123213123123312321312312313131231231231232131312'; 

// Put your private key's passphrase here: 
$passphrase = '*********'; 
$a = 1; 
// Put your alert message here: 
//$message = $_GET['msg']; 
$message = $_POST['msg'];  
//////////////////////////////////////////////////////////////////////////////// 
//$myString= $_GET['id']; 
$myString= $_POST['id']; 

$registrationIds =explode(',', $myString); 

foreach ($registrationIds as $deviceid) 
    { 

$ctx = stream_context_create(); 
stream_context_set_option($ctx, 'ssl', 'local_cert', 'cert.pem'); 
stream_context_set_option($ctx, 'ssl', 'passphrase', $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, 
    'badge' => $a, 
    'sound' => 'default' 
    ); 

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

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

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

echo $result ; 

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

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

在AppDelegate中的Xcode

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 
    { 
     UIUserNotificationSettings *settings = 
     [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | 
     UIUserNotificationTypeBadge | 
     UIUserNotificationTypeSound 
              categories:nil]; 
     [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 
     [[UIApplication sharedApplication] registerForRemoteNotifications]; 
    } 
    else 
    { 
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
     UIRemoteNotificationTypeAlert | 
     UIRemoteNotificationTypeBadge | 
     UIRemoteNotificationTypeSound]; 
    } 
+0

你是否將設備令牌發送給服務器? –

+0

是的,我正在發送 –

回答

0

您正在使用的生產APNS服務器:

ssl://gateway.push.apple.com:2195 

爲了使您的應用接收推送通知,你必須建立與簽名生產證書。您可以通過生成Ad Hoc構建來實現這一點。

如果你想發送推送到您的設備以開發模式運行的應用程序,你必須通知推到沙箱APNS服務器:

ssl://gateway.sandbox.push.apple.com:2195 

更多細節在蘋果文檔:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html