使用离子框架从设备检索设备令牌 [英] Retrieve device token from device using ionic framework

查看:113
本文介绍了使用离子框架从设备检索设备令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ionic 来开发应用程序,我需要获取推送通知的设备令牌,但遇到了麻烦。应用程序没有收到通知,但我仍然需要在用户登录应用程序时发送设备令牌(例如,我需要获取设备令牌而不接收通知)。我也尝试使用Cordova推送通知插件。

I am using ionic to develop an application and I need to get the device token for push notifications, but having trouble. The application isn't receiving notifications, but I still need to send device token when user login into the application (e.g. I need to get device token without receiving notifications). I tried using the Cordova push notification plugin also.

推荐答案

使用下面的插件获取设备令牌值。
离子插件添加phonegap-plugin-push --variable SENDER_ID =GCM_PROJECT_NUMBER

use the below plugin to get the device token value. ionic plugin add phonegap-plugin-push --variable SENDER_ID="GCM_PROJECT_NUMBER"

请使用以下代码获取设备令牌值。

please use the below code to get the device token value.

.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
        push = PushNotification.init({
            android: {
                senderID: "61426985247",
                sound: "true",
                vibrate: "true",
                forceShow: "true"
            },
            browser: {
                pushServiceURL: 'http://push.api.phonegap.com/v1/push'
            },
            ios: {
                alert: "true",
                badge: true,
                sound: 'false'
            },
            windows: {}
        });



        push.on('registration', function(data) {

            alert("device token" + data.registrationId);

        });
    });
})

这篇关于使用离子框架从设备检索设备令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆