0
  1. first "npm install --save @types/apn"
  2. In app.component.ts

AppComponent

import { Component } from '@angular/core';
import { NavController, NavParams, LoadingController } from 'ionic-angular';

//import apn from 'apn';
import * as apn from 'apn';

@Component({
  selector: 'page-a',
  templateUrl: 'a.html'
})
export class a {
    constructor(public navCtrl: NavController, public navParams: NavParams) {
       var options = {
          token: {
            key: "key.p8",
            keyId: "1234567",
            teamId: "987654"
          },
          production: false
        };

        var apnProvider = new apn.Provider(options);

        var note = new apn.Notification();

        note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
        note.badge = 3;
        note.sound = "ping.aiff";
        note.alert = "\uD83D\uDCE7 \u2709 You have a new message";
        note.payload = { 'messageFrom': 'John Appleseed' };

        apnProvider.send(note, 'devicetoken').then((result) => {
                // see documentation for an explanation of result

        });
   }
}
  1. run then got error: Uncaught ReferenceError: Invalid left-hand side in assignment
Poul Kruijt
  • 69,713
  • 12
  • 145
  • 149
denny
  • 1
  • 2
  • Your error does not seem to be related to `apn` though. Can you give the line number of where it goes wrong? And possibly also post the given code – Poul Kruijt Feb 01 '17 at 14:11
  • the error on forge.js:52, you can ref this picture:[error pic](http://i.imgur.com/cT9l8qh.png). – denny Feb 01 '17 at 14:26

1 Answers1

0

Couple of things, can you first post the entire class? Because this piece of code is pretty unintelligible.

You should change your import statement to:

import * as apn from 'apn';

You should install apn using:

npm install node-apn --save

You should install the typings using:

npm install --save-dev @types/apn
Poul Kruijt
  • 69,713
  • 12
  • 145
  • 149
  • change three statement you ask, but don't change the result. Got the same error: Uncaught ReferenceError: Invalid left-hand side in assignment. And sorry for can't explain clearly, I try to change the question statement,hope to show the whole picture. – denny Feb 01 '17 at 14:13