【问题标题】:Phonegap GCM onNotification Return Result : OkPhonegap GCM onNotification 返回结果:好的
【发布时间】:2015-05-02 12:13:06
【问题描述】:

我正在使用 phonegap push plugin

我的问题是我在真实设备中收到了onNotification 功能警报消息“结果:Ok”,我也检查了。

我的 config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.xxxxxxxxxxx.xxxxxxxxxxxx" version="6.2" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>xxxxxxxx</name>
    <description>
       The #1 Mobile App to Earn Money on xxxxxx .
    </description>
    <author email="xxxxxx" href="http://xxxxxx.com">
        xxxxxx Team
    </author>
    <icon src="icon.png" />
    <content src="index.html" />
    <access origin="*" />
    <feature name="PushPlugin">
    <param name="android-package" value="com.plugin.gcm.PushPlugin" />
   </feature>
   <feature name="NetworkStatus">
    <param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager" />
    </feature>
    <gap:plugin name="org.apache.cordova.InAppBrowser" />
    <icon src="icon.png" />
    <icon gap:platform="android" height="114" src="res/icon/android/icon-xxhdpi.png" width="114" />
    <icon gap:platform="android" height="96" src="res/icon/android/icon-xhdpi.png" width="96" />
    <icon gap:platform="android" height="72" src="res/icon/android/icon-hdpi.png" width="72" />
    <icon gap:platform="android" height="48" src="res/icon/android/icon-mdpi.png" width="48" />
    <icon gap:platform="android" height="36" src="res/icon/android/icon-ldpi.png" width="36" />
    <icon gap:platform="ios" src="res/icon/ios/icon.png" />
    <engine name="android" spec="^4.0.0" />
</widget>

并且还在 manifest.xml 文件中添加了 Internet 权限。

我的 gcm 代码:​​

window.plugins.pushNotification.register(successHandler, errorHandler, {
    ecb      : 'onNotificationGCM',
    senderID : 'xxxxxxxxxxxxxx'// Google Project ID.
});

// Method to handle device registration for Android.
var onNotificationGCM = function(e) {
    alert(e.event);
    if('registered' === e.event) {
        // Successfully registered device.
        alert(e.regid);
    }
    else if('error' === e.event) {
        // Failed to register device.
        alert(e.msg);
    }
    else if('message' === e.event) {
        //mesage recived 
        alert(e.payload.message);
    }

};

// result contains any message sent from the plugin call
function successHandler (result) {
    alert('result = ' + result);
}

// result contains any error description text returned from the plugin call
function errorHandler (error) {
    alert('error = ' + error);
}

如何从 gcm 获取注册 ID。

【问题讨论】:

    标签: android cordova phonegap-plugins phonegap-pushplugin


    【解决方案1】:

    这是使用 GCM 进行 phonegap 通知的一个很好的例子,它工作正常 Link is here

    【讨论】:

    • java 到 javascript 调用的问题。在 CordovaWebView 中 sendJavascript 方法已被弃用。因此任何其他方式都可用于从 java 调用 javascript。
    【解决方案2】:
    1. 尝试自动安装。
    2. 确保您的项目 ID 正确
    3. 仔细检查您的 deviceready 事件是否定义正确并已触发。

    注意:如果您收到OK 响应,则表示插件正在正常工作,没有任何错误。您没有获得注册 ID 的原因可能是肤浅的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 2013-07-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多