# Push Plugin can't get registrationId value only

**URL:** <https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321>\
**Category:** ionic-v3\
**Created:** [April 4, 2017, 9:46am UTC](https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321 "2017-04-04T09:46:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mystearica](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@Mystearica](https://forum.ionicframework.com/u/Mystearica)\
**Post date:** [April 4, 2017, 9:46am UTC](https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321/1 "2017-04-04T09:46:09Z")

</div>

Hi!

I have the code from the docs, and I’m trying to access the registradionId property from the object registration.

But if I use the normal way to access the object, registration.registrationId, it says that I cant.

Is there any way to obtain only the registrationId, and not the object itself?? Actually thats what I did in ionic1 data.registrationId, but I can’t in Ionic2.

Thank you!!!

---

<div class="post-metadata">

**Author:** ![drjoju](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/drjoju/32/107876_2.png) [@drjoju](https://forum.ionicframework.com/u/drjoju)\
**Post date:** [April 4, 2017, 10:20am UTC](https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321/2 "2017-04-04T10:20:54Z")

</div>

Hi, I use this code and works well in iOS and Android.

In my app.components.ts constructor I have this call this.initPushNotification();

And the code of this function is  
\> initPushNotification(){

> ```
> if (!this.platform.is('cordova')) {
> console.warn("Push notifications not initialized. Cordova is not available - Run in physical device");
> return;
> }
> let push = Push.init({
> android: {
> senderID: "XXXXXXXXX", //this.configApp.gcm_sender_id, // Your sender id variable
> icon: 'icon', // Small icon file name without extension
> iconColor: '#a4b1e2' // Icon background color for Android 5 and newer
> },
> ios: {
> alert: "true",
> badge: false,
> sound: "true"
> },
> windows: {}
> });
> 
> ```

> ```
> push.on('registration', (data) => {
> console.log("device token ->", data.registrationId);
> //TODO - send device token to server
> this.storage.set('pushRegisterDisabled', true);
> 
> ```

> ```
> var oldRegId = localStorage.getItem('pushRegistrationId');
> if (oldRegId !== data.registrationId) {
> // Save new registration ID
> localStorage.setItem('pushRegistrationId', data.registrationId);
> // Post registrationId to your app server as the value has changed
> }
> 
> ```

> ```
> // Sólo si estamos autenticados, enviamos el PUSH TOKEN
> if (this.usuario) {
> let platformName = "Navegador";
> 
> ```

> ```
> if ((<any>window).cordova) {
> if (this.platform.is('ios')) {
> platformName = "ios";
> } else if (this.platform.is('android')) {
> platformName = "android";
> }
> }
> 
> ```

> ```
> // Se registra durante el login
> // We need to save registration id somewhere on server to be able to send push notifications to this device
> //this.storeDeviceToken(platformName.toLowerCase(), data.registrationId);
> }
> });
> 
> ```

> ```
> push.on('notification', (data) => {
> console.log('message', data.message);
> //if user using app and push notification comes
> if (data.additionalData.foreground) {
> // if application open, show popup
> let confirmAlert = this.alertCtrl.create({
> title: 'New Notification',
> message: data.message,
> buttons: [{
> text: 'Ignore',
> role: 'cancel'
> }, {
> text: 'View',
> handler: () => {
> //TODO: Your logic here
> // self.nav.push(DetailsPage, {message: data.message});
> }
> }]
> });
> confirmAlert.present();
> } else {
> //if user NOT using app and push notification comes
> //TODO: Your logic on click of push notification directly
> // self.nav.push(DetailsPage, {message: data.message});
> console.log("Push notification clicked");
> }
> });
> push.on('error', (e) => {
> console.log("PUSH error -> " + e.message);
> });
> }
> 
> ```

Best regards

---

<div class="post-metadata">

**Author:** ![Mystearica](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@Mystearica](https://forum.ionicframework.com/u/Mystearica)\
**Post date:** [April 4, 2017, 10:25am UTC](https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321/3 "2017-04-04T10:25:22Z")

</div>

Hi!

The thing is that I can’t access data.registrationId, it just says that parameter doesn’t exist, but in the object, is there.

[![](https://i.imgur.com/5qFMgBg.png) ](https://i.imgur.com/5qFMgBg.png)

But as you can see here, its there.

[![](https://i.imgur.com/cA7xrXf.png) ](https://i.imgur.com/cA7xrXf.png)

---

<div class="post-metadata">

**Author:** ![drjoju](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/drjoju/32/107876_2.png) [@drjoju](https://forum.ionicframework.com/u/drjoju)\
**Post date:** [April 4, 2017, 10:35am UTC](https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321/4 "2017-04-04T10:35:48Z")

</div>

The only diference is the calling method

push.on(‘registration’, (data) =\> {

push.on(‘registration’).subscribe(data)

Ionic version?

---

<div class="post-metadata">

**Author:** ![Mystearica](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@Mystearica](https://forum.ionicframework.com/u/Mystearica)\
**Post date:** [April 4, 2017, 11:19am UTC](https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321/5 "2017-04-04T11:19:41Z")

</div>

I’m using ionic 2, I tried before your methods, but I cant use it.

---

<div class="post-metadata">

**Author:** ![drjoju](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/drjoju/32/107876_2.png) [@drjoju](https://forum.ionicframework.com/u/drjoju)\
**Post date:** [April 4, 2017, 11:22am UTC](https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321/6 "2017-04-04T11:22:26Z")

</div>

I’m using the last release.

Cordova CLI: 6.5.0  
Ionic Framework Version: 2.2.0  
Ionic CLI Version: 2.2.1  
Ionic App Lib Version: 2.2.0  
Ionic App Scripts Version: 1.1.4  
ios-deploy version: Not installed  
ios-sim version: Not installed  
OS: Windows 10  
Node Version: v6.10.0  
Xcode version: Not installed

My config.xml has

Sorry I can`t see the problem

---

<div class="post-metadata">

**Author:** ![Mystearica](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@Mystearica](https://forum.ionicframework.com/u/Mystearica)\
**Post date:** [April 4, 2017, 11:59am UTC](https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321/7 "2017-04-04T11:59:13Z")

</div>

This is the error i get when I try to use push.on  
[![](https://i.imgur.com/VN4kOXk.png) ](https://i.imgur.com/VN4kOXk.png)

---

<div class="post-metadata">

**Author:** ![drjoju](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/drjoju/32/107876_2.png) [@drjoju](https://forum.ionicframework.com/u/drjoju)\
**Post date:** [April 4, 2017, 12:52pm UTC](https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321/8 "2017-04-04T12:52:23Z")

</div>

I’m importing push

import {Push} from ‘ionic-native’;

And I don’t add to the constructor. I don’t use private push: Push. I use directly.

let push = Push.init({…

I’m using this version in config.xml

plugin name=“phonegap-plugin-push” spec="~1.10.0"

---

<div class="post-metadata">

**Author:** ![Mystearica](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@Mystearica](https://forum.ionicframework.com/u/Mystearica)\
**Post date:** [April 5, 2017, 7:56am UTC](https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321/9 "2017-04-05T07:56:45Z")

</div>

Hi!

Which version of ionic-native do you have? I can’t import Push the way you do it, because thats the old way, now should be imported with @ionic-native/push

---

<div class="post-metadata">

**Author:** ![drjoju](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/drjoju/32/107876_2.png) [@drjoju](https://forum.ionicframework.com/u/drjoju)\
**Post date:** [April 5, 2017, 9:27am UTC](https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321/10 "2017-04-05T09:27:20Z")

</div>

Hi Mystearica,  
I think, I have 3.4.4 version.

```
"@ionic-native/app-availability": "^3.4.4",
"@ionic-native/camera": "^3.4.4",
"@ionic-native/core": "^3.4.4",
"@ionic-native/file": "^3.4.4",
"@ionic-native/market": "^3.4.4",
"@ionic-native/media": "^3.4.4",
"@ionic-native/media-capture": "^3.4.4",
```

---

<div class="post-metadata">

**Author:** ![StukOngeluk](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@StukOngeluk](https://forum.ionicframework.com/u/StukOngeluk)\
**Post date:** [April 7, 2017, 9:20am UTC](https://forum.ionicframework.com/t/push-plugin-cant-get-registrationid-value-only/85321/11 "2017-04-07T09:20:30Z")

</div>

You should pass the type “any” to the data like:

```auto
pushy.on('registration').subscribe((data:any) => {
      //Your code
   })

```

Now it won’t error anymore 😉
