2017-10-09 33 views
0
  • 的PhoneGap-插件推
  • 离子框架:3.6.0
  • 离子应用程序脚本:2.1.4
  • 方芯:4.1.3
  • 角度编译CLI:4.1.3
  • 节点:6.11.1
  • OS平台:视窗10
  • 导航平台:Win32的
  • 用户代理:Mozilla/5.0(Windows NT 10.0; Win64平台; X64) 为AppleWebKit/537.36(KHTML,例如Gecko)铬/ 60.0.3112.113 Safari浏览器/ 537.36离子3应用程序不重定向到特定的页面上点击通知

    它完美时,应用程序是开放&接收通知,它会自动当该应用是重定向到特定page.But关闭&我点击通知,它不重定向到page.It只启动应用程序。

pushObject的通知码

pushObject.on('notification').subscribe((notification: any) => { 
     console.log('Received a notification', notification); 
     if(notification.additionalData.type=="news"){ 
     this.NewsAndEventsDetails(notification.additionalData.type_id); 
     }else if(notification.additionalData.type=="notice"){ 
     this.getNoticesSingle(notification.additionalData.type_id); 
     }else if(notification.additionalData.type=="bill"){ 
     this.getBillsSingle(notification.additionalData.type_id); 
     }else{ 
     let prompt = this.alertCtrl.create({ 
      title: notification.title, 
      message: notification.message 
     }); 
     prompt.present(); 
     } 
    }); 

回答

0

从我的身边,同样的问题出现,

我解决了这个问题,执行下列操作步骤。

Install FCM plugin 

ionic cordova plugin add cordova-plugin-fcm 

npm install --save @ionic-native/fcm 

Get google-services.json file GoogleService-Info.plist file from fcm for your registered project. 

Add google-services.json in android platform root like /platforms/android/google-services.json 


Add GoogleService-Info.plist file in ios platform like /patforms/ios/ProjectName/Resoures/Resoures/GoogleService-Info.plist 
or also add at /platforms/android/GoogleService-Info.plist 

Now run the project on android and ios device you get fcmid. 
Store fcmid to the server. 

Server side code is like this. 


public function sendNotification($sectionName){ 
     $url = 'https://fcm.googleapis.com/fcm/send'; 
     $fields = array (
       'to' => "fcmId", 
       'notification' => array (
         "body" => "Hello test", 
         "title" => "Title", 
         "icon" => "myicon", 
         "sound" => "default", 
         "click_action" => "FCM_PLUGIN_ACTIVITY", // this is important for ontapped 
       ), 
       'data' => array('rollno' => "test", 
           'name' => "manish", 
           'activitySection' => $sectionName), 
           'priority' => 'high', 
     ); 
     $fields = json_encode ($fields); 
     echo $fields; 
      $headers = array (
        'Authorization: key=' . "fcm server key", 
        'Content-Type: application/json' 
      ); 

     $ch = curl_init(); 
     curl_setopt ($ch, CURLOPT_URL, $url); 
     curl_setopt ($ch, CURLOPT_POST, true); 
     curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers); 
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields); 

     $result = curl_exec ($ch); 
     curl_close ($ch); 
    } 

This is on app 


fcmInitilization() { 
    if (!this.plt.is('cordova')) { 
     console.warn('Push notifications not initialized. Cordova is not available - Run in physical device'); 
     return; 
    } 
    this.fcm.onNotification().subscribe(data => { 
     if (data.wasTapped) { 
     // do onTapped work here means app in background 
     } else { 
     let confirmAlert = this.alertCtrl.create({ 
      title: 'New Notification', 
      message: data.title, 
      buttons: [{ 
      text: 'Ignore', 
      role: 'cancel' 
      }, { 
      text: 'View', 
      handler:() => { 
       //TODO: Your logic here 
      } 
      }] 
     }); 
     confirmAlert.present(); 
     }; 
    }) 
    } 
+0

Thnaks为您的答复。我没有使用cordova-plugin-fcm,我正在使用phonegap-plugin-push。 –

+0

嗨,对于https://github.com/phonegap/phonegap-plugin-push 检查点击数据是否即将到来。 如果不在服务器端添加这些代码。 “data”=> array( “title”=>'Test Push', “message”=>'Push number 1', “info”=>'super secret info', “content-available”= >'1') – Manish

相关问题