angularjs - 用ionic解析推送通知

标签 angularjs cordova ionic-framework parse.js

我正在尝试建立一个带有解析的推送通知,以处理收到的通知。

我使用了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));
});

警报成功只是未能显示,所以我想它没有用,或者我没有做正确的事。

最佳答案

使用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');
        }
    })

关于angularjs - 用ionic解析推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29771478/

相关文章:

angularjs - Angular grunt build(来自 yeoman)破坏了我的应用程序

javascript - 如何根据属性值调用作用域函数

angularjs - 如何在 AngularJs 1.6 组件的 Controller 中使用绑定(bind)

javascript - 如何在 jqueryMoblie 的本地存储中存储项目

javascript - ionic 2 : ReferenceError: webpackJsonp is not defined

javascript - 通过指令的 AngularJS 小部件/插件

ios - meteor ios cordova ENOENT,没有这样的文件或目录

javascript - 带phonegap 2.0的childbrowser

css - ionic 4 自定义 ionic 菜单宽度在 ios 中不起作用

javascript - Cordova Ionic 键盘插件在 “Init” 上完全禁用