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在。如何解决仁慈的帮助 –