2016-11-08 239 views
0

使用FCM插件FCM註冊令牌 - 科爾多瓦項目,試圖生成註冊令牌。生成用科爾多瓦

FCMPlugin.getToken(function(token) { 
       console.log('reg token: ' + token); 
       alert(token); 
      }, function(err) { 
       console.log('error retrieving token: ' + err); 
      }) 

我需要一個清晰度,如何將發件人ID作爲參數傳遞給上述請求?

回答

0

谷歌已經創建了火力地堡的推送通知。 Google強烈建議使用FCM而不是舊的GCM。

在目前的FCM科爾多瓦推送通知插件,您不需要「發件人ID」。

您對您的應用程序提供您的應用程序的名字和一些細節後註冊您的應用程序在http://www.console.firebase.google.com

然後,谷歌將爲您提供兩個文件。

1)谷歌services.json
2)GoogleService-Info.plist中

如果您正在開發Android應用,那麼你需要保持以.json文件在android的根目錄。

或者如果您正在開發IOS應用程序,那麼您需要將.plist文件保存在android根目錄中。

然後在onDeviceReady功能index.js文件中使用此代碼

FCMPlugin.getToken(
     function(token){ 
     //alert(token); 
     $.post("http://example.com/api/addToken",{tok:token},function(data){ 
      if(data) 
      { 
       // DO some function here if the token is added to the database 
      }     
     }); 
     }, 
     function(err){ 
     console.log('error retrieving token: ' + err); 
     alert('error retrieving token: ' + err); 
     } 
    ) 

這就是全部。檢查這是否適用於你或至少不爲我工作.. :)