2

나는 정말로 문제가 어디에 있는지 모른다. 라이브러리 ApnsPHP를 사용하여 푸시 알림을 보내고 있습니다. 다른 스크립트도 시도했지만 작동하지 않습니다.iPhone이 푸시 알림을받지 않는 이유는 무엇입니까?

이 튜토리얼 (http://code.google.com/p/apns-php/wiki/CertificateCreation)을 사용하여 푸시 인증서를 생성하고이를 Apple 개발자 웹 사이트에 저장합니다. 나는 sample_push.php에 넣은 iphone에서 올바른 토큰을 얻을 수 있습니다.

MacBook Pro 13 형, Mac OS 910, Mac OS Lion을 가지고 있습니다.

vojta:~/dev/www/application$ php sample_push.php 
Fri, 13 Apr 2012 16:23:24 +0200 ApnsPHP[6478]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195... 
Fri, 13 Apr 2012 16:23:32 +0200 ApnsPHP[6478]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195. 
Fri, 13 Apr 2012 16:23:32 +0200 ApnsPHP[6478]: INFO: Sending messages queue, run #1: 1 message(s) left in queue. 
Fri, 13 Apr 2012 16:23:32 +0200 ApnsPHP[6478]: STATUS: Sending message ID 1 [custom identifier: Message-Badge-3] (1/3): 109 bytes. 
Fri, 13 Apr 2012 16:23:33 +0200 ApnsPHP[6478]: INFO: Disconnected. 

내가 실행 "PHP는 sample_push.php"나는 오류를 얻을 것이다, 그러나 또한 내가 내 아이폰에 어떤 푸시 알림을받지 못한 경우

.

소스 sample_push.php :

// Using Autoload all classes are loaded on-demand 
require_once 'ApnsPHP/Autoload.php'; 

// Instanciate a new ApnsPHP_Push object 
$push = new ApnsPHP_Push(
    ApnsPHP_Abstract::ENVIRONMENT_SANDBOX, 
    'server_certificates_bundle_sandbox.pem' 
); 

// Set the Root Certificate Autority to verify the Apple remote peer 
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem'); 

// Connect to the Apple Push Notification Service 
$push->connect(); 

// Instantiate a new Message with a single recipient 

$message = new ApnsPHP_Message('xxxx'); // i put my token here 

// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method 
// over a ApnsPHP_Message object retrieved with the getErrors() message. 
$message->setCustomIdentifier("Message-Badge-3"); 

// Set badge icon to "3" 
//$message->setBadge(3); 

// Set a simple welcome text 
$message->setText('Hello APNs-enabled device!'); 

// Play the default sound 
$message->setSound(); 

// Set the expiry value to 30 seconds 
$message->setExpiry(30); 

// Add the message to the message queue 
$push->add($message); 

// Send all messages in the message queue 
$push->send(); 

// Disconnect from the Apple Push Notification Service 
$push->disconnect(); 

// Examine the error message container 
$aErrorQueue = $push->getErrors(); 
if (!empty($aErrorQueue)) { 
    var_dump($aErrorQueue); 
} 

나는 또한 내가 정말 무엇을 해야할지하지 않습니다

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

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

// Put your alert message here: 
$message = 'My first push notification!'; 

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

$ctx = stream_context_create(); 
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.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' 
    ); 

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

(또한 작동하지) 훨씬 더 간단한 스크립트를 시도하고 있었다. 제발 누군가 도와주세요.

답변

2

나는 그것을 풀었다. Xcode가 iOS 팀 프로비저브 프로필에 앱을 서명했기 때문입니다. 이 프로필을 삭제하면 푸시 알림이 작동하기 시작했습니다.

+1

모든 제공 프로필을 제거했지만 여전히 응답이 없습니다. 어떤 생각? –

+0

@SyedOsama, 나는 같은 문제에 직면했다. 이 문제에 대한 해결책을 찾았습니까? – jacobian

+0

@Jacobian, 예.이 문제를 해결했습니다. 1) .pem 파일에 RSA 비공개 키가 있는지 확인하십시오. –

0

Apple에 푸시 알림을 보내면 상태 코드가 반환됩니다. 수신중인 상태 코드는 무엇입니까? 다시 0을 얻고 있습니까?

Status codes 
0 No errors encountered 
1 Processing error 
2 Missing device token 
3 Missing topic 
4 Missing payload 
5 Invalid token size 
6 Invalid topic size 
7 Invalid payload size 
8 Invalid token 
255 None (unknown) 
+0

답장을 보내 주셔서 감사합니다.하지만 답을주지 않는 함수 stream_socket_client를 사용하는 PHP 스크립트. 서버 측에서 무엇을 사용합니까? 난 정말 뭔가를 찾고 또한 디버깅 할 수 있습니다 .... –

+0

Fri, 06 Sep 2013 13:50:26 +0200 ApnsPHP [4632] : INFO : Trying ssl : //gateway.push.apple.com : 2195. .. 금요일, 06 9 월 2013 13:50:27 +0200 ApnsPHP [4632] : 정보 : ssl : //gateway.push.apple.com : 2195에 연결되었습니다. Fri, 06 Sep 2013 13:50:27 +0200 ApnsPHP [4632] : INFO : 메시지 대기열을 보내고 대기열에 남아있는 메시지 1 : 1 개를 실행합니다. Fri, 06 9 월 2013 13:50:27 +0200 ApnsPHP [4632] : 상태 : 보내는 메시지 ID 1 [맞춤 식별자 : 설정되지 않음 (1/3) : 55 바이트. 금요일, 06 9 월 2013 13:50:28 +0200 ApnsPHP [4632] : 정보 : 연결이 끊어졌습니다. 이 메시지를 받았는데 동일한 문제가 있습니다. –

관련 문제