3

タイトルが適切かどうかはわかりませんが..

PushNotification Pluginと UrbanAirshipを使用したプッシュ通知付きの cordova 1.9 アプリがあります。すべて正常に動作します。

通知からアプリを起動/再開するときに、アプリの特定のページを開きたいと思います。

Javascriptを使用してそれは可能ですか? Objective-C を読んでいるとき、私は完全に迷っています。

4

3 に答える 3

3

通知により、JSON 構造を理解するのに問題が発生します。

そうではない:

if(notifications.length > 0){

しかし:

if(notifications.notifications.length > 0){

配列はオンです:notifications.notifications[]構造。

于 2012-09-14T14:42:06.300 に答える
0

どのようにページを読み込もうとしているのかはわかりませんが、最も簡単な方法は、保留中の通知を JavaScript で呼び出してwindow.location.hrefから、必要なページを読み込むことです。

アプリケーションの開始時に保留中の通知がある場合、この手順を使用して特定のタスクを実行しています。

function registerAirship() {
    console.log("ready to register for airship");
    window.plugins.pushNotification.registerDevice({alert:true, badge:true, sound:true},function(status) {
       if (status.deviceToken) {
           window.token = status.deviceToken;
           if (status) {
               registerUAPush(token, "https://go.urbanairship.com/", key, key1, function(){
                    window.plugins.pushNotification.getPendingNotifications(function(notifications) {
                        if(notifications.length > 0){
                            var note = notifications[0];
                            if(note.applicationLaunchNotification == "1"){
                                // use the note.aps and redirect to required page
                            }
                        }
                    });
               });
           } else {
             alert("Registration Error: " + status);
           }
       }
   });
}
于 2012-07-13T18:59:47.937 に答える
0

私は数日前にあなたの立場にいました。私は、objective-c をハッキングするのが最も簡単だと判断しました。

そう。

1) プッシュ通知 (AppDelegate.m) を処理する関数を見つけ、objective-c が通知を処理するための実行を開始した後に js 関数を呼び出しました。その行の後、私はこれをしました:

[viewController.webView stringByEvaluatingJavaScriptFromString:@"opensometab()"];

2) Web アプリ アプリケーションのルートで、これを pushnotification.js ファイルに追加しました (どこにでも配置できるはずですが、ここに配置したかったのです)。** 私の JS 機能はビューポート内のタブをアクティブにすることでしたので、あなたのものは異なるかもしれません。

function opensometab(){
    var tabPanel = Ext.Viewport.down('tabpanelname');
    tabPanel.setActiveItem(3); //index number 3 
}
于 2012-07-13T20:08:44.060 に答える