gpt4 book ai didi

php - 如何使用 phonegap 发送推送通知并解析

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:29:30 26 4
gpt4 key购买 nike

我正在使用 php、jquery 和 phonegap 创建一个 android 应用程序。我在谷歌中搜索了很多东西,但找不到发送推送通知。我看过这个Phonegap and Parse.com Push Notifications IOS但我不清楚如何获得 deviceToken。

我也看到了下面的

https://parse.com/questions/php-rest-example-of-targeted-push

我了解如何发送通知。但是没有 devicetoken 我怎么能发送推送通知。anybosy 可以告诉我如何获取设备 token 吗?

最佳答案

我关注了this tutorial这直接工作得很好。它还解释了如何获取设备 token 。

它会提醒您重新输入,但您也可以将手机连接到计算机并阅读 logcat 文件。 (可以使用android SDK中的“监控”工具)

更新示例

大部分步骤基本上都是devgirls tutorial I mentioned before的直接复制

在 Windows 命令提示符下:

  1. phonegap create quickpush
  2. cd quickpush
  3. phonegap local build android
  4. phonegap local plugin add https://github.com/phonegap-build/PushPlugin

  5. 我跳过了这个,我没有将文件复制到 www 目录。我只是把它留在原处。

  6. 添加 <script type="text/javascript" src="PushNotification.js"></script>到 index.html

  7. 添加 <gap:plugin name="com.phonegap.plugins.pushplugin" />到config.xml(这与站点不同,解决了不支持的错误)

  8. 复制/js/index.js 文件中 onDeviceReady 函数中的推送代码。显然从谷歌添加你自己的 key

    alert('device ready');
    try {
    var pushNotification = window.plugins.pushNotification;
    pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"--SENDER ID FROM GOOGLE--","ecb":"app.onNotificationGCM"});
    } catch (ex) {
    alert('error: ' + ex);
    }
  9. 复制/js/index.js 文件中的回调处理函数

    successHandler: function(result) {
    alert('Callback Success! Result = '+result)
    },
    errorHandler:function(error) {
    alert(error);
    },
    onNotificationGCM: function(e) {
    switch( e.event )
    {
    case 'registered':
    if ( e.regid.length > 0 )
    {
    console.log("Regid " + e.regid);
    alert('registration id = '+e.regid);
    }
    break;

    case 'message':
    // this is the actual push notification. its format depends on the data model from the push server
    alert('message = '+e.message+' msgcnt = '+e.msgcnt);
    break;

    case 'error':
    alert('GCM error = '+e.msg);
    break;

    default:
    alert('An unknown GCM event has occurred');
    break;
    }
    }
  10. 构建应用:phonegap remote build android

关于php - 如何使用 phonegap 发送推送通知并解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20421688/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com