iOS设备令牌&推送通知离子

时间:2016-08-09 08:20:24

标签: ios ionic-framework push-notification

有人可以帮助我们使用离子来获取ios上的设备令牌。我已经设法使用Xcode获取设备令牌但是是否可以仅使用离子获取设备令牌?

我需要在用户登录应用时添加设备令牌

2 个答案:

答案 0 :(得分:1)

试试这个

使用此插件

   cordova plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX"

之后添加此

in to ionicPlatform.ready

var push = PushNotification.init({
    "android": {
        "senderID": "SENDER-ID"
    },
    "ios": {"alert": "true", "badge": "true", "sound": "true"}, 
    "windows": {} 
});

push.on('registration', function(data) {
    console.log("registration event");
    //here is your registration id
    console.log(data.registrationId);
});

答案 1 :(得分:0)

我可能很晚才回答你的问题,你的回答如下

  1. 将您的离子更新为最新版本i,e v2及更高版本。
  2. 然后创建一个项目并添加此插件
  3.   

    cordova插件添加phonegap-plugin-push --variable   SENDER_ID =“XXXXXXXXX

    1. 接下来转到src / app / app.component.ts文件并在platform.ready()之后添加此代码。然后(()

      var push = Push.init({
          android: {
            senderID: "XXXXXXXXX"
          },
          ios: {
            alert: "true",
            badge: true,
            sound: 'false'
          },
          windows: {}
        });
        push.on('registration', (data) => {
          console.log(data.registrationId);
          alert(data.registrationId.toString());              
        });
      

      push.on('notification',(data)=> {     的console.log(数据);      警报(“嗨,是推送通知”);   });

    2. 根据苹果指南执行所有认证部分(如果 有任何问题请做评论)。
    3. 最后在java或php或ionic.io中实现推送通知服务器端!一切顺利......
相关问题