簡體   English   中英

離子發送帶有附加網址的Parse推送通知

[英]Ionic sending Parse push notification with attached url

我一直在忙於基於離子的新應用程序。 這是一個新環境,因此我有很多事情要探索。

我遇到了一些問題,並在整個互聯網上進行搜索以找到解決方案,卻找不到解決我的問題的解決方案。 所以我希望你們中的一個知道解決方案。

我正在嘗試使用解析將通知發送到我的設備。 效果很好,但是現在我想發送一個附帶的uri,這樣我就可以單擊已收到的通知來打開特定頁面。 問題是我不知道如何正確發送附加的uri並在設備上接收到該uri才能對其執行操作。

我希望你們中的一些人知道解決方案。

我正在使用ASP.NET與工作正常的客戶端發送通知。

var parsePush = new ParsePush();


                // sending to all with your own data
                parsePush.Data = new Dictionary<string, object>
                {
                    {"alert", txtMessage.Text},// this is replacement for parsePush.Alert                   
                    {"sound", "notify.caf"},// for ios
                    {"badge", "Increment"}// for ios notification count increment on icon
                    //{"category", "http://google.nl" }
                };
                parsePush.SendAsync().Wait(); 

對於離子方面,我沒有任何事件可以接收通知並使用它。 我剛收到通知,並重定向到應用程序的主頁。

如果有不清楚的細節,請通知我。

非常感謝!

我通過搜索整個互聯網解決了這個問題。

我做的第一件事是在服務器端取消parsePush.data中的類別注釋(請參閱問題中的代碼)。 在類別中,我定義uri。 我要做的下一件事是在我的app.js中添加“ ParsePushPlugin.on”。 接收或打開通知時使用這些事件。

我將此代碼添加到.run-> $ ionicPlatform.ready中的app.js中。

ParsePushPlugin.getInstallationId(function (id) {
        alert(id);
        storage.set('parseId', id);
    }, function (e) {
        alert('error');
    });

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

    //customEvt can be any string of your choosing, i.e., chat, system, upvote, etc.
    ParsePushPlugin.on('receivePN:chat', function (pn) {
        alert('yo i can also use custom event to keep things like chat modularized');
    });

    ParsePushPlugin.on('openPN', function (pn) {
        //you can do things like navigating to a different view here
        //alert('Yo, I get this when the user clicks open a notification from the tray');
        $state.go(pn.category)
    });

如您所見,“ ParsePushPlugin.on('openPn')”具有pn作為參數,其中包含來自已接收和打開的通知的所有數據。 此通知還包含從服務器端傳遞的“類別(uri)”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM