应用程序关闭时,离子2推送通知无效

时间:2017-10-04 03:37:04

标签: php android ionic-framework google-cloud-messaging phonegap-pushplugin

应用关闭时,我没有收到推送通知。 但是,当应用程序处于后台/前台时,它可以正常工作。

以下是app.component.ts中代码的一部分

  initPushNotification()
  {
    // to initialize push notifications
    const options: PushOptions = {
       android: {
          icon: 'small-icon',
          forceShow: true
       },
       ios: {
          alert: 'true',
          badge: true,
          sound: 'false'
       },
       windows: {}
    };
    const pushObject: PushObject = this.push.init(options);
    pushObject.on('notification').subscribe((notification: any) => {
      //Notification Display Section
      alert(JSON.stringify(notification));
    });
    pushObject.on('registration').subscribe((registration: any) => {
      alert(registration.registrationId);
    });
    pushObject.on('error').subscribe(error => {
      alert('Error with Push plugin' + error);
    });
  }

这是我发送推送通知的PHP代码

<?php
    public function androidNotification($title, $message, $registrationIds, $addData) {
        // API access key from Google API's Console
        define( 'API_ACCESS_KEY', 'accesskeyhere' );
        // prep the bundle
        $msg = array
        (
            'message' => $message,
            'title' => $title,
            'addData' => $addData,
            'vibrate' => 1,
            'sound' => 1,
            'largeIcon' => 'large_icon',
            'smallIcon' => 'small_icon'
        );
        $fields = array
        (
            'registration_ids' => $registrationIds,
            'data' => $msg
        );

        $headers = array
        (
            'Authorization: key=' . API_ACCESS_KEY,
            'Content-Type: application/json'
        );
        $ch = curl_init();
        curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
        curl_setopt( $ch,CURLOPT_POST, true );
        curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
        curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
        curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
        curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
        $result = curl_exec($ch );
        curl_close( $ch );
    }

这是什么问题?我正在使用离子平台。

我正在寻找论坛,但没有运气。我没有找到任何解决方案。

1 个答案:

答案 0 :(得分:0)

您可以参考此thread。尝试更改优先级。在此page中声明,2的设置优先级使其有效。

相关问题