沃梦达 / 编程问答 / php问题 / 正文

如何使用phonegap和解析发送推送通知

how to send push notification using phonegap and parse(如何使用phonegap和解析发送推送通知)

本文介绍了如何使用phonegap和解析发送推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am creating an android app using php,jquery and phonegap. I have searched so many things in google but i cant find to send push notification. I have seen this Phonegap and Parse.com Push Notifications IOS But i am not clear ho can i get deviceToken.

我也看过下面的

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

我了解如何发送通知.但是没有设备令牌我怎么能发送推送通知.谁能告诉我如何获得设备令牌.

I understood how to send notification. But without devicetoken how can i send push notification. Can anybosy tell me how can i get the device token.

推荐答案

我关注了 本教程 直接有效.它还解释了如何获取设备令牌.

I followed this tutorial which worked very well directly. It also explains how to get the device token.

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

It is alerted for you to type it over, but you can also hook your phone up to your computer and read the logcat files. (You can use the "monitor" tool in the android SDK)

更新示例

大多数步骤基本上是我之前提到的 devgirls 教程

在 Windows 命令提示符下:

In windows command prompt:

  1. phonegap 创建快速推送
  2. cd quickpush
  3. phonegap 本地构建 android
  4. phonegap 本地插件添加 https://github.com/phonegap-build/PushPlugin

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

I skipped this, I dont copy the file to the www dir. I just leave it where it is.

添加到 index.html

add <script type="text/javascript" src="PushNotification.js"></script> to index.html

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

add <gap:plugin name="com.phonegap.plugins.pushplugin" /> to config.xml (this is different from site and solves not supported error)

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

Copy the push code in the onDeviceReady function in /js/index.js file. Obviously add your own key from google

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);
}

  • 复制/js/index.js文件中的回调处理函数

  • Copy the callback handler function in /js/index.js file

    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;
        }
    }
    

  • 构建应用程序:phonegap remote build android

    这篇关于如何使用phonegap和解析发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

  • 本文标题为:如何使用phonegap和解析发送推送通知

    基础教程推荐