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

2023-07-16php开发问题
0

本文介绍了如何使用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和解析发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

    The End

  • 相关推荐

    PHP实现DeepL翻译API调用
    DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
    2025-08-20 php开发问题
    168

    PHP通过phpspreadsheet导入Excel日期数据处理方法
    PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
    2024-10-23 php开发问题
    287

    mediatemple - 无法使用 codeigniter 发送电子邮件
    mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
    2024-08-23 php开发问题
    11

    Laravel Gmail 配置错误
    Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
    2024-08-23 php开发问题
    16

    将 PHPMailer 用于 SMTP 的问题
    Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
    2024-08-23 php开发问题
    4

    关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
    Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
    2024-08-23 php开发问题
    17