【问题标题】:pusher api notification not working on android Emulator as well as browserpusher api 通知在 android Emulator 和浏览器上不起作用
【发布时间】:2013-10-12 16:15:54
【问题描述】:

我使用 Pusher API 进行通知,但它为我工作。我的网站上有组合框,该组合框部署在 azure 上,在此组合框中三个状态显示待处理的完整请求超时,此时用户将更改组合框中的状态,因此 ajax 请求将发送到我添加通道和事件绑定的 json 文件。

我也在模拟器上收到消息

10-12 12:13:15.544: D/CordovaLog(1257): file:///android_asset/www/index.html: Line 28 : Pusher : State changed : unavailable -> connected
10-12 12:13:15.544: I/Web Console(1257): Pusher : State changed : unavailable -> connected at file:///android_asset/www/index.html:28
10-12 12:13:15.553: D/CordovaLog(1257): file:///android_asset/www/index.html: Line 28 : Pusher : Event sent : {"event":"pusher:subscribe","data":{"channel":"dispatcher_channel"}}
10-12 12:13:15.553: I/Web Console(1257): Pusher : Event sent : {"event":"pusher:subscribe","data":{"channel":"dispatcher_channel"}} at file:///android_asset/www/index.html:28
10-12 12:13:17.613: D/CordovaLog(1257): file:///android_asset/www/index.html: Line 28 : Pusher : Event recd : {"event":"pusher_internal:subscription_succeeded","data":{},"channel":"dispatcher_channel"}
10-12 12:13:17.613: I/Web Console(1257): Pusher : Event recd : {"event":"pusher_internal:subscription_succeeded","data":{},"channel":"dispatcher_channel"} at file:///android_asset/www/index.html:28
10-12 12:13:17.623: D/CordovaLog(1257): file:///android_asset/www/index.html: Line 28 : Pusher : No callbacks on dispatcher_channel for pusher:subscription_succeeded
10-12 12:13:17.623: I/Web Console(1257): Pusher : No callbacks on dispatcher_channel for pusher:subscription_succeeded at file:///android_asset/www/index.html:28

json.php 这是天蓝色

function updateRequestStatus($params)
    {
        global $api;

        $params = json_decode($params, true);

        $requestStatus = PageHelper::sanitizeInput($params['requestStatus'], FILTER_SANITIZE_STRING);
        $requestID = PageHelper::sanitizeInput($params['requestID'], FILTER_SANITIZE_NUMBER_INT);

        if(strtolower($requestStatus) == "completed")
        {
            $message = "User Response Has been Sent ";
            $pusher = new Pusher( APP_KEY, APP_SECRET, APP_ID );
            $data = array('message' => $message);
            $pusher->trigger( 'dispatcher_channel', 'dispatcher_Response', $data );
        }

        return $api->updateRequestStatus($requestStatus, $requestID);
    }

以及我在 android 上使用的 index.html。

<!DOCTYPE HTML>
<html>
<head>
<title></title>

<meta name="viewport" content="width=device-width,initial-scale=1"/>

<!--  JavaScript -->


<script src="http://js.pusher.com/2.1/pusher.min.js" type="text/javascript"></script>
<script src="js/cordova.js" type="text/javascript"></script>

<script type="text/javascript">
    // Enable pusher logging - don't include this in production
    Pusher.log = function(message) {
      if (window.console && window.console.log) {
        window.console.log(message);
      }
    };

    var pusher = new Pusher('APP_KEY');
    var channel = pusher.subscribe('dispatcher_channel');
    channel.bind('notification', function(data) {
    setTimeout('getNotification()', 1000);
    channel.bind('dispatcher_Response', function(data) {}); 
    }); 
    function getNotification()
    {
        navigator.notification.alert("status changed", function() {});
    }
  </script>

</head>
</body>
</html>

【问题讨论】:

    标签: php android pusher


    【解决方案1】:

    日志显示您已连接并订阅了dispatcher_channel 频道。

    当您运行json.php 时,Pusher 调试控制台会显示什么?见:http://pusher.com/docs/debugging#pusher_debug_console

    它是否显示来自json.php 的消息到达 Pusher?

    如果没有,那么您应该查看调试 PHP 代码。看: https://github.com/pusher/pusher-php-server#debugging

    如上所述,客户端功能似乎按预期工作。

    【讨论】:

    • 你能告诉我为什么没有弹出通知,因为我检查了 android 模拟器的 cat 日志,它告诉我消息即将到来但没有在模拟器上弹出
    • 在您上面的代码 (channel.bind('dispatcher_Response', function(data) {});) 中,您没有对事件数据做任何事情。
    猜你喜欢
    • 2013-05-22
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 2021-08-06
    • 2020-05-20
    • 2019-02-14
    • 2016-04-23
    相关资源
    最近更新 更多