Push Notification 2.0


#1

Has anyone actually gotten Push to work with Ionic 2.0 final ?


#2

What seems to be the issue?
Is there anything that you are having issues with?
Mind sharing some code and explaining a bit more?


#3

Thank you for responding!! I have been having trouble getting push to work just by following the instructions!! I have tried both in my app which is currently in beta in the play store and by creating a new blank app.
This is the error that I get when I run Ionic Serve --lab, however I think this might be normal. When I build an apk and load it on my phone it just does nothing. Does anything stick out to you? Thank you for your help.

polyfills.js:3 Error: Uncaught (in promise): Error: Push plugin not found! See logs.
    Error: Push plugin not found! See logs.
        at main.js:64646
        at EventEmitter.once (main.js:41609)
        at Push.register (main.js:64628)
        at MyApp.initPushNotification (main.js:111225)
        at main.js:111220
        at t.invoke (polyfills.js:3)
        at Object.onInvoke (main.js:38889)
        at t.invoke (polyfills.js:3)
        at e.run (polyfills.js:3)
        at polyfills.js:3
        at main.js:64646
        at EventEmitter.once (main.js:41609)
        at Push.register (main.js:64628)
        at MyApp.initPushNotification (main.js:111225)
        at main.js:111220
        at t.invoke (polyfills.js:3)
        at Object.onInvoke (main.js:38889)
        at t.invoke (polyfills.js:3)
        at e.run (polyfills.js:3)
        at polyfills.js:3
        at s (polyfills.js:3)
        at s (polyfills.js:3)
        at polyfills.js:3
        at t.invokeTask (polyfills.js:3)
        at Object.onInvokeTask (main.js:38880)
        at t.invokeTask (polyfills.js:3)
        at e.runTask (polyfills.js:3)
        at i (polyfills.js:3)
        at HTMLDocument.invoke (polyfills.js:3)
    o @ polyfills.js:3

config.xml

  <plugin name="phonegap-plugin-push" spec="~1.9.2">
    <variable name="SENDER_ID" value="xxxxxxxxxxx"/>
  </plugin>

.io-config.json (the api key here is the legacy api key under settings --> API Keys, I have tried using the API token as well with no different )
{"app_id":"34e6c194","api_key":"xxx"}

app.module.ts

   import {CloudSettings, CloudModule} from '@ionic/cloud-angular';`      
   import { AngularFireModule } from 'angularfire2';

   const cloudSettings: CloudSettings= {
        'core': {
           'app_id': '34e6c194',
         },
        'push': {
        'sender_id': 'xxxxx',
        'pluginConfig': {
        'ios': {
           'badge': true,
           'sound': true
        },
        'android': {
          'iconColor': '#343434'
        }
      }
     }
  }

const COMMON_CONFIG = {
    apiKey: "xxx",
    authDomain: "xxx",
    databaseURL: "xxx",
    storageBucket: "xxxx",
    messagingSenderId: "xxx"
};


@NgModule({
  declarations: [
    MyApp,
    Page1,
    IonCoverHeader,
    Hearing,
    HearingDetail,
    Prehearing,
    SearchAttorney,
    SearchAttorneyDetail,
    SearchDebtor,
    SearchDebtorDetail,
    SearchCaseNumber,
    SearchCaseNumberDetail,
    CreditorMeeting,
    CreditorMeetingDetail,
    LocationPage,
    Sacramento,
    Fresno,
    Modesto,
    Bakersfield,
    IonCategories,
    Settings
  ],
  imports: [
    IonicModule.forRoot(MyApp),
    CloudModule.forRoot(cloudSettings),
    AngularFireModule.initializeApp(COMMON_CONFIG)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    Page1,
    Hearing,
    HearingDetail,
    Prehearing,
    SearchAttorney,
    SearchAttorneyDetail,
    SearchDebtor,
    SearchDebtorDetail,
    SearchCaseNumber,
    SearchCaseNumberDetail,
    CreditorMeeting,
    CreditorMeetingDetail,
    LocationPage,
    Sacramento,
    Fresno,
    Modesto,
    Bakersfield,
    Settings
  ],
 // providers: [{provide: ErrorHandler,  useClass: IonicErrorHandler}, DataService, Storage]
  providers:[DataService, Storage],
})
export class AppModule {}

app.component.ts

  constructor(public platform: Platform, public push: Push, public storage: Storage) {
      this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      StatusBar.styleDefault();
      Splashscreen.hide();
      this.initPushNotification();
    });
  }

 initPushNotification()
  {
    this.push.register().then((t: PushToken) => {
      return this.push.saveToken(t);
    }).then((t: PushToken) => {
      console.log('Token saved:', t.token);
    });

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

#4

Hi,

Having the same issue.
Error in :0:0 caused by: Cannot read property ‘config’ of undefined


#5

Well, we also had our journey on this subject… First we fixed it by removing the entry in the config.xml and adding this block into the package.json right next to the other cordovaPlugins:

{
“variables”: {
“SENDER_ID”: “xxx”
},
“locator”: “phonegap-plugin-push”
}

After some ionic package updates this didnt work anymore. So we moved back to managing the dependency in the config.xml and … tada … it works for us when using explictly phonegap-plugin-push 1.8.4

It didnt work with 1.9.2, 1.9.4 or 1.20.2

We are building the apk/ipa using ionic package service and the phonegap-plugin-push is included now.