(Ionic 2 Push) Android device token registration issue

Hello All,

I’ve been attempting to get push notification working in my app and have been having trouble getting the device to register. Right now I have the dead basics from the documentation just to try and get it moving. I have added an alert inside of the then() after the device registers which it has never hit. I have also tried in VS 2017 browser simulator which also didn’t work, wasn’t expecting it to anyway.

I have tried testing the app both through side loading onto my phone and also through Ionic View both to no avail. I Firebase is setup and configured as is the app itself.

Any help or guidance would be appreciated!

Thanks!

What plugins and libraries are you using to implement push in your app?
What service are you trying to use to send push?

I am using ionic/cloud-angular Push service and trying to send a notification through the ionic dashboard. I did integrate the ionic Auth service thinking that had something to do with it and that was also didn’t help it.

Show us some code please, then.

Surely, This is my app.module.ts

import { CloudSettings, CloudModule } from '@ionic/cloud-angular';
...
const cloudSettings: CloudSettings = {
    'core': {
        'app_id': 'aff7d862',
    },
    'push': {
        'sender_id': '1014472767909',
        'pluginConfig': {
            'ios': {
                'badge': true,
                'sound': true
            },
            'android': {
                'iconColor': '#343434'
            }
        }
    }
};

@NgModule({
    declarations: [
        MyApp,
        Login,
        Artists,
        Artist,
        Calendar,
        PopoverPage,
        AddapptmodalPage,
        ModifyapptmodalPage,
        Register,
        Chathub,
        Chat,
        SwipeVertical,
        FormatTime
    ],
    imports: [
        IonicModule.forRoot(MyApp),
        BrowserModule,
        FormsModule,
        ElasticModule,
        HttpModule,
        CalendarModule.forRoot(),
        CommonModule,
        CloudModule.forRoot(cloudSettings)
    ],
    bootstrap: [IonicApp],
    entryComponents: [
        MyApp,
        Login,
        Artists,
        Artist,
        Calendar,
        PopoverPage,
        AddapptmodalPage,
        ModifyapptmodalPage,
        Register,
        Chathub,
        Chat
    ],
    providers: [
        { provide: ErrorHandler, useClass: IonicErrorHandler },
        UserSingleton,
        SendBirdCtrl,
        FormatTime,
        AjaxMethods,
        { provide: HAMMER_GESTURE_CONFIG, useClass: MyHammerConfig }]
})

Then on the login page (which is the root of the app) there is this

import { Push, PushToken } from '@ionic/cloud-angular';
...
constructor(public navCtrl: NavController, private http: Http, private menu: MenuController, public currUser: UserSingleton,
        public modalCtrl: ModalController, public platform: Platform, public push: Push)
    {
        this.push.register().then((t: PushToken) =>
        {
            return this.push.saveToken(t);
        }).then((t: PushToken) =>
        {
            this.currUser.setValue("devicetoken", t.token);
            });

        this.push.rx.notification()
            .subscribe((msg) =>
            {
                alert(msg.title + ': ' + msg.text);
            });
    }

Right now it is a straight copy paste from https://docs.ionic.io/services/push/ just so I can get it working then I’ll go off making it more complex, but not even the base code from the docs works.

Try putting the push stuff in app/app.component.ts and there in the constructor and inside platform.ready().

alright, I’ll have to give it a try later tonight when I’m home but hopefully that’s it! I’ll let you know, thank you!

1 Like

Well that still didn’t work, however, after scowering​ the internet tirelessly I can across OneSignal and am now using that for push notifications took about 20 minutes to setup and get working and it fully integrates with Ionic so at least it working now! Thanks for the help anyway Sujan!