我不懂PHP脚本。基本上我是一个iPhone应用开发者。我想从服务器发送Apple推送通知。我正在遵循本教程中的APNS流程http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2。我使用api.php脚本将值存储在MySQL表中。
我想知道以下几行中发生了什么。
$stmt = $this->pdo->prepare('SELECT * FROM usersTable WHERE udid = ? LIMIT 1');
$stmt->execute(array($udid));
$user = $stmt->fetch(PDO::FETCH_OBJ);
writeToLog('handleMessage SELECT * FROM usersTable WHERE udid = ? LIMIT 1');
if ($user !== false)
{
// Put the sender's name and the message text into the JSON payload
// for the push notification.
$payload = $this->makePayload($user->nickname, $text);
writeToLog('handleMessage Payload: ' . $payload);
// Find the device tokens for all other users who are registered
// for this secret code. We exclude the device token of the sender
// of the message, so he will not get a push notification. We also
// exclude users who have not submitted a valid device token yet.
$stmt = $this->pdo->prepare("SELECT device_token FROM usersTable WHERE secret_code = ? AND device_token <> ? AND device_token <> '0'");
$stmt->execute(array($user->secret_code, $user->device_token));
$tokens = $stmt->fetchAll(PDO::FETCH_COLUMN);
writeToLog('handleMessage Tokens: ' . $tokens); // It is showing value like 'Array'
// Send out a push notification to each of these devices.
// If the senders secret code is differ from registered secret code this foreach loop won't execute
foreach ($tokens as $token)
{
writeToLog('Sending payload and token to addPushNotification Function');
writeToLog('token in foreach loop token: ' . $token);
$this->addPushNotification($token, $payload);
}
}
我希望任何人都能理解这个PHP脚本的功能。如何在日志文件中打印$ stmt和$ tokens?你能解释一下这些线路上发生了什么吗?请帮我。提前谢谢。
答案 0 :(得分:0)
更改
writeToLog('handleMessage Tokens: ' . $tokens);
到
writeToLog('handleMessage Tokens: ' . print_r($tokens, 1));