0
  1. 第一个“npm install --save @types/apn”
  2. 在 app.component.ts

应用组件

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. 运行然后得到错误:未捕获的ReferenceError:分配中的左侧无效
4

1 回答 1

0

几件事,你能先发布整个班级吗?因为这段代码非常难以理解。

您应该将导入语句更改为:

import * as apn from 'apn';

您应该apn使用以下方式安装:

npm install node-apn --save

您应该使用以下方法安装类型:

npm install --save-dev @types/apn
于 2017-02-01T13:07:22.167 回答