2016-09-21 10 views
0

Ionic 2では、ユーザーが現在アプリケーションにいるときにイベントを処理しようとしているため、警告メッセージがポップアップして別のビューに移動できます。私のアプリのコンストラクタで、私は次のコードを持っている:私は通知を送信するとアプリケーションがIonic 2で開かれているときにプッシュ通知を処理する

export class MyApp { 
    private rootPage: any; 

    constructor(private platform: Platform, private app: App, private push: Push) { 
    if (UserService.isLoggedIn()) { this.rootPage = PickupPage; } 
    else { this.rootPage = LoginPage; } 

    console.log('We are here! We are here! We are here!'); 
    platform.ready().then(() => { 
     // Okay, so the platform is ready and our plugins are available. 
     // Here you can do any higher level native things you might need. 
     console.log('Registering notifications handler'); 
     this.push.rx.notification().subscribe(msg => { 
     alert(msg.title); 
     console.log('Got something!'); 
     console.dir(msg); 
     }); 
     StatusBar.styleDefault(); 
    }); 
    } 
} 

を、Android上で私は、通知がオンにAndroid上のプルダウンバーが、アプリの内部には、コンソールまたは警告に来るとget私は何も得られません。コンソールメッセージまたはアラートはなく、通知センターには通知はありません。

§ ionic -v 
2.0.0-beta.37 

答えて

0

私は、次のように、仕事にpush.pluginConfig.android.senderIDCloudSettingssenderIDを追加する必要がありましたように見えます:

それは CloudSettingsオブジェクトdoesnのように思えるように、その100%が答えであれば
const cloudSettings: CloudSettings = { 
    'core': { 'app_id': '***' }, 
    'push': { 
    'sender_id': '***', 
    'pluginConfig': { 
     'ios': { 'badge': true, 'sound': true }, 
     'android': { 'senderID': '***', 'iconColor': '#d1b561' } 
    } 
    } 
} 

わかりませんアプリのインストール後に変更したい

編集

私は少しさらに作業の事を得ているように思えます。ドキュメントによると、アプリが開くたびにthis.push.register()に電話する必要があります。私は、次のようapp.tsで更新私のアプリのコンストラクタによって通知がはるかに安定見える押すことが判明:

platform.ready().then(() => { 
    // Register to receive push notifications 
    this.push.register().then((token: PushToken) => { 
    // Send the token to Ionic cloud so we can send to it through the API 
    return this.push.saveToken(token) 
    }); 
    // Setup our handler so we can perform actions on push notifications 
    this.push.rx.notification().subscribe(msg => { 
    console.log(`Received ${msg.title}: ${msg.message}`); 
    if (msg.app.asleep || msg.app.closed) { 
     // The app is being opened from a notification 
    } else { 
     // The app was already open when the notification was received 
    } 
    }); 
    ... 
}); 
+0

あなたがプッシュ通知を行うことができます場合は、あなたの答えを更新してください私のような多くの人がプッシュ通知 –

+0

に苦労しているので、 @モホンゴピ私は答えを更新しました。私は明日までそれを答えとすることはできません。アプリが開かれるたびに通知を登録する必要があるようです。私はそれを十分に把握するのに十分なほど掘り下げたわけではありませんが、ここでは 'register'のコードですhttps://github.com/driftyco/ionic-cloud/blob/master/src/push/push.ts#L214 –

関連する問題