0
- 第一 「NPM安裝--save @類型/ APN」
- 在app.component.ts
AppComponent如何使node-apn正確工作在angular2上?
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
});
}
}
- 運行,那麼得到的錯誤:未捕獲的ReferenceError:無效的左手側分配
不是:
您應該使用安裝分型:
您應該使用安裝
apn
與'apn'有關。你能給出哪裏出錯的行號?並且還可能發佈定的代碼 – PierreDuc上forge.js錯誤:52, 你可以參考這樣的畫面:[錯誤圖](http://i.imgur.com/cT9l8qh.png)。 – denny