Rahul Sharma
Rahul Sharma

Reputation: 622

IONIC 3: Push notification click do nothing

I am using ionic 3 application and have to implement the push notification in my app. Everything working fine notification comes on my mobile and even if app is running, on('notification') triggering well. But problem is, when app not in running state (in background) and when notification arrives and on click notification on(notification) not triggering.

app.component.ts

pushSetup(){
    const options: PushOptions = {
       android: {
            senderID: '********'
       },
       ios: {
           alert: 'true',
           badge: true,
           sound: 'false'
       }
    };

    const pushObject: PushObject = this.push.init(options);


    pushObject.on('notification').subscribe((notification: any) => {
        console.log(notification);
        if(notification.additionalData.type == 'wordpress'){
            this.zoom.authenticate(notification.additionalData.user_id, "user_encrypted_secret").then((res: AuthCallbackResponse) => {
                console.log(res.successful);
            }).catch(err => console.log(err));
        }
    });

    pushObject.on('registration').subscribe((registration: any) => {
        console.log('Device registered', registration);
        this.storage.set('device_token', registration.registrationId);
    });

    pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}

And my server code from where notification comes:

$optionBuilder = new OptionsBuilder();
        $optionBuilder->setTimeToLive(60*20);

        $title = 'WP Registration Request';

        $notificationBuilder = new PayloadNotificationBuilder($title);
        $notificationBuilder->setBody('New Wordpress Registration Request')
                            ->setSound('default');

        $dataBuilder = new PayloadDataBuilder();
        $dataBuilder->addData(['token' => $registerToken,'type'=>'wordpress','website'=>$request->domain,'mobile'=>$request->mobile,'user_id'=>$model->id]);

        $option = $optionBuilder->build();

        $notification = $notificationBuilder->build();
        $data = $dataBuilder->build();

        $token = $model->device_token;

        $downstreamResponse = FCM::sendTo($token, $option, $notification, $data);

on server side i am using Lumen Framework and using brozot/laravel-fcm package for send notification.

Can any one tell me whats the wrong in my code?

Upvotes: 1

Views: 522

Answers (1)

Sudarshana Dayananda
Sudarshana Dayananda

Reputation: 5265

Set content-available to 1 in your push payload.

Eg:

data: {
  additionalData: {
    content-available :  "1"
    priority : "high"
  },
  image : "icon"
  message : "This is sample message"
  sound : "default"
  title : "New Comment"
}

More Information

Upvotes: 2

Related Questions