Ionic 3中PhoneGap推送插件报错:senderID缺失及options常量问题求助
Got it, let's tackle these two issues you're facing—they're actually pretty common when setting up push notifications with this stack, even if you followed the official docs. Here's what you need to do:
1. Resolve the 'senderID is Missing' Error
The official docs might have omitted a critical detail: the Android platform requires a senderID (this is your Firebase Cloud Messaging project number) to work properly. Without it, the plugin throws that missing senderID error every time.
Update your options object to include the senderID in the Android config:
const options: PushOptions = { android: { senderID: '1234567890' // Replace this with your Firebase project's sender ID }, ios: { alert: 'true', badge: true, sound: 'false' }, windows: {}, browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' } };
To get your senderID:
- Open your Firebase project dashboard, navigate to Settings > Cloud Messaging, and copy the "Sender ID" value listed there.
2. Fix the Type Error Hovering Over options
This is a TypeScript type mismatch issue. The PushOptions interface from @ionic-native/push expects the android property to include a senderID—since you were missing it before, TypeScript flags it as an error.
Once you add the senderID as above, this error should disappear automatically. But if it persists, double-check your dependency versions to ensure compatibility with Ionic 3:
- Uninstall any incompatible versions first:
npm uninstall @ionic-native/push cordova plugin remove phonegap-plugin-push - Reinstall versions that work with Ionic 3:
npm install @ionic-native/push@4.x --save cordova plugin add phonegap-plugin-push@2.x --save
Ionic 3 relies on version 4.x of @ionic-native packages, and phonegap-plugin-push 2.x is the last stable release compatible with this setup.
After making these changes, rebuild your project (ionic cordova build android or ios) and the errors should be gone.
内容的提问来源于stack exchange,提问作者user3397260

