使用 Ionic 解析推送通知

9
我正在尝试使用Parse设置推送通知以处理接收到的通知。
我使用了phonegap-parse-plugin插件,并成功地设置了它。
我的问题是我无法处理收到的通知。我希望可以根据通知JSON参数将用户重定向到通知页面。
因此,我决定切换到parse-push-plugin,但我的问题是我甚至无法显示已注册框; 它甚至找不到ParsePushPlugin方法。
我按照简单的教程进行操作,并将其添加到我的app.js文件中。
ParsePushPlugin.register(
    { appId:"xxx", clientKey:"xxx", eventKey:"myEventKey" }, //will trigger receivePN[pnObj.myEventKey]
    function() {
        alert('successfully registered device!');
    },
    function(e) {
        alert('error registering device: ' + e);
});

ParsePushPlugin.on('receivePN', function(pn){
    alert('yo i got this push notification:' + JSON.stringify(pn));
});

警告成功的提示未能显示,我猜它可能无法工作或者是我没有做正确的事情。

现在可以工作了。我不得不加载 parse js 库。 - Uchenna
1
这是一个初学者错误,但我们都曾经犯过,很高兴听到你成功解决了! - user4495161
参数中的eventkey是什么? - raju
@raju,以防你有自定义事件键。 - Uchenna
可能需要将此作为您问题的答案发布。 - Huey
1个回答

1

使用phonegap-plugin-push。它易于实现和使用。

配置:

    var push = PushNotification.init({
        "android": {
            "senderID": "Your-sender-ID",
            "forceShow": true, // To show notifications on screen as well
            "iconColor": "#403782",
            "badge": "true",
            "clearBadge": "true" // To clear app badge
        },
        "ios": {
            "alert": "true",
            "badge": "true",
            "clearBadge": "true",
            "sound": "true",
            "forceShow": "true"
        },
        "windows": {}
    });

设备注册:
    push.on('registration', function(data) {
            localStorage.setItem('pushToken', data.registrationId); // Save registration ID
    });

处理通知
    push.on('notification', function(data) {
        console.log(data);
        // Handle all requests here
        if (data.additionalData.$state == "mystate") {
            $state.go('app.conversations');
        }
    })

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接