我正在iOS/android中創建應用程序。當設備收到遠程通知時,didReceiveRemoteNotification
應該被調用。但它沒有發生。通過APNS發送msg!我的服務器端代碼是爲下:didReceiveRemoteNotification未被調用
$deviceToken = $obj_listener->ref_id;
// Put your private key's passphrase here:
$passphrase = 'blahblah';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '/var/www/mobileapp/TestAppCK.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){
$this->log->debug("Failed to connect: $err $errstr" . PHP_EOL);
exit("Failed to connect: $err $errstr" . PHP_EOL);
}
$badge_count = $obj_listener->badge_count + 1;
// Create the payload body
$body['aps'] = array(
//'alert' => 'Message received',
'sound' => 'default',
'badge' => $badge_count,
'msg_id' => $this->msg_id,
//'user_key' => $obj_listener->ref_id,
'email' => $obj_listener->to_email_id
);
// 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));
// Close the connection to the server
fclose($fp);
我的Objective-C端的代碼是爲下:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
//UIWebView *NewWebView = NULL;
NSLog(@"didReceiveRemoteNotification function");
return;
}
我已經檢查了在服務器端代碼的設備令牌。該設備是正確的。 爲什麼上述函數沒有被調用。提前致謝。
如果您的應用程序的推送通知爲開啓,請檢查您的iPhone設置 –
另請確保您使用的是正確的設置配置文件(鏈接到您將在服務器代碼中使用的證書)。 –
它不在全部到達設備。 – clint