>我只是遵循这个 https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/TYPESCRIPT.md 指导
在我的应用程序.组件.ts 文件中
import { Push, PushToken } from '@ionic/cloud-angular';
constructor(platform: Platform) {
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();
});
var push = PushNotification.init({
android: {
senderID: '1234XXX9' //GCM project number
},
ios: {
alert: 'true',
badge: true,
sound: 'false'
},
windows: {}
});
push.on('registration', (data) => {
console.log(data.registrationId);
});
push.on('notification', (data) => {
console.log(data.message);
console.log(data.title);
console.log(data.count);
console.log(data.sound);
console.log(data.image);
console.log(data.additionalData);
});
push.on('error', (e) => {
console.log(e.message);
});
}
我在这一行上收到错误var push = Push.init({
当我给 Ionic Build Android 时,我在上面一行出现错误错误。
如果我缺少任何要点,请告诉我。
错误
[10:18:05] typescript: src/app/app.component.ts, line: 24
Cannot find name 'PushNotification'.
L24: var push = PushNotification.init({
L25: android: {
[10:18:05] transpile failed
[10:18:05] ionic-app-script task: "build"
[10:18:05] Error: Error
您正在使用的推送是来自 Ionic 的云服务。
要使用离子云插件,您必须使用离子云设置您的项目。此处的设置步骤
在此处查看推送特定文档。您应该注入它而不是尝试全局变量。
constructor(platform: Platform, private push:Push) {
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.
this.push.register().then((t: PushToken) => {
return this.push.saveToken(t);
}).then((t: PushToken) => {
console.log('Token saved:', t.token);
});
StatusBar.styleDefault();
Splashscreen.hide();
});