3

나는 이오니아 2를 사용 중이며 푸시 알림을 작동 시키려고합니다.cordova-plugin-fcm - FCMPlugin이 정의되지 않았습니다.

내 앱을 Firebase에 등록하고 성공적으로 알림을 푸시 할 수 있습니다.

이제 앱에서 알림을 푸시 할 수 있도록 설정해야합니다. 그래서 다음 Cordova Plugin (cordova-plugin-fcm)을 사용하기로 결정했습니다.

질문 1

나는 그것이 내 이오니아 응용 프로그램에서 다음을 수행하여 지시의 따르

app.ts

declare var FCMPlugin; 
... 

    initializeApp() { 
    this.platform.ready().then(() => { 
... 
    FCMPlugin.getToken(
     function (token) { 
.... 

내가 런타임에 다음과 같은 오류가 :

EXCEPTION: Error: Uncaught (in promise): ReferenceError: FCMPlugin is not defined

어떻게 해결할 수 있습니까? 귀하의 응용 프로그램에서 알림을 보내려면

질문 2

는 코르도바 플러그인 (cordova-plugin-fcm)는 다음을 지시합니다

//POST: https://fcm.googleapis.com/fcm/send 
//HEADER: Content-Type: application/json 
//HEADER: Authorization: key=AIzaSy******************* 
{ 
    "notification":{ 
    "title":"Notification title", //Any value 
    "body":"Notification body", //Any value 
    "sound":"default", //If you want notification sound 
    "click_action":"FCM_PLUGIN_ACTIVITY", //Must be present for Android 
    "icon":"fcm_push_icon" //White icon Android resource 
    }, 
    "data":{ 
    "param1":"value1", //Any data to be retrieved in the notification callback 
    "param2":"value2" 
    }, 
    "to":"/topics/topicExample", //Topic or single device 
    "priority":"high", //If not set, notification won't be delivered on completely closed iOS app 
    "restricted_package_name":"" //Optional. Set for application filtering 
} 

이도 타이프 라이터 또는 자바 스크립트가 아닙니다. 그럼 어디로 간다? 나는 이해하지 못한다. 모든 조언을 부탁드립니다. 당신은 FCMPlugin.js을 가져야한다

답변

1

앱 예의 플러그인 디렉토리에 JS 파일의 경로 찾을 수 당신의 HTML 인덱스 파일에 포함 된 MyFCM \ 플러그인 \ 코르도바 - 플러그인 - FCM \ www가 FCMPlugin.js \를

app.controller('AppCtrl', function(FCMPlugin,$scope,$cordovaToast,$cordovaDialogs,ionPlatform) { 
    // call to register automatically upon device ready 
    ionPlatform.ready.then(function (device) { 
    console.log('I am working'); 
    FCMPlugin.onNotification(
     function(data){ 
     if(data.wasTapped){ 
      //Notification was received on device tray and tapped by the user. 
      $cordovaDialogs.alert(data.notification.body); 
     }else{ 
      //Notification was received in foreground. Maybe the user needs to be notified. 
      $cordovaDialogs.alert(data.notification.body); 
      //$cordovaToast.showShortCenter(JSON.stringify(data)); 
     } 
     }, 
     function(msg){ 
     $cordovaToast.showShortCenter('onNotification callback successfully registered: ' + msg); 
     }, 
     function(err){ 
     $cordovaToast.showShortCenter('Error registering onNotification callback: ' + err); 
     } 
    ); 
    }); 
}) 
+1

이것이 작동합니까 ???? –

+0

내 cordova 앱에서 일했습니다. – Amjad

0

나는 동일한 오류가있었습니다.

시도해보십시오. 그것은 확실히 당신을 도울 것입니다.

if (typeof FCMPlugin != 'undefined') { 

     FCMPlugin.getToken(function (token) { 
      console.log(token); 
     }); 
    } 

"if 조건"위에 놓고 내 문제를 해결합니다.

관련 문제