0

我想使用FCM在離子應用中發送通知,但首先我想使用FCM獲取設備標記。我已經嘗試了下面的方法來獲取設備token.working。但我想使用FCM獲取設備令牌。任何人都知道如何獲得,請幫助。使用FCM在離子中獲取設備Tocken

angular.module('starter', ['ionic']) 

.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
    var push = new Ionic.Push({ 
     "debug": true 
    }); 

    push.register(function(token) { 
     console.log("My Device token:",token.token); 
     push.saveToken(token); // persist the token in the Ionic Platform 
    }); 
    }); 
}) 
+0

嗯,你可能看着很舊的文件。檢查了這一點http://stackoverflow.com/questions/37653251/firebase-cloud-messaging-with-ionic-app/39262282#39262282 這,如果你想發送推送通知所有下載應用程序的設備 –

回答

0

有了這個插件:https://github.com/fechanique/cordova-plugin-fcm 您可以訪問您的設備令牌是這樣的:用火力地堡是這個插件需要

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

一切。

玩得開心:)

+0

在哪裏把這個代碼放在哪個文件中? –

+0

無論你想獲得令牌,只要在你的push.register函數上! –

+0

我已將此代碼粘貼到onclick函數中......但我給出了該錯誤.FCMPlugin沒有在Scope中定義爲 $ scope.click(http:// localhost:8100/js/app.js:34:1) at fn(eval在。如何解決仁慈的幫助 –