0

Can someone help on how to get device token on ios using ionic only. I've managed to get device token using Xcode but is it possible to get device token using ionic only?

I need to to add the device token when the users log in the app

1
  • Under the hood its plugin talking native to javascript. You can use plugin where you won't to have code in native. Commented Dec 27, 2016 at 11:15

2 Answers 2

4

Try this

using this plugin

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

after that adding this

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);
});
Sign up to request clarification or add additional context in comments.

Comments

0

I may be very late in answering your question, your answer is as below

  1. Update your ionic to latest version i,e v2 and above.
  2. Then create a project and add this plugin

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

  1. Next goto src/app/app.component.ts file and add this code after platform.ready().then(()

    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(data); alert("Hi, Am a push notification"); });

  2. Perform all the certification part according to apple guidelines(if any problem please do comment).
  3. Finally implement push notification server side either in java or php or ionic.io ! All the best...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.