1

我不知道 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?你能解释一下这些线路发生了什么吗?请帮我。提前致谢。

4

1 回答 1

0

改变

writeToLog('handleMessage Tokens: ' . $tokens);

writeToLog('handleMessage Tokens: ' . print_r($tokens, 1));

于 2012-05-28T07:22:27.820 回答