Ionic 1 iOS应用推送通知问题:Cordova FCM插件iOS端失效求助
Hey there! Let’s tackle your iOS push notification issues with Ionic + Cordova FCM, plus walk through a full setup guide for Ionic 1 specifically.
iOS FCM Push Notification Troubleshooting (Your Current Issue)
Since Android works fine, the problem is almost certainly tied to iOS-specific configuration gaps. Here’s what to check step by step:
Apple Developer Account Setup
- Verify that Push Notifications is enabled for your App ID in the Apple Developer Portal. You’ll need to generate both development and production APNs certificates, then upload them to your Firebase project’s Cloud Messaging settings.
- Ensure your Provisioning Profile includes Push Notification permissions. Regenerate it if you’ve made changes to the App ID, then download and install it in Xcode.
Plugin & Firebase Configuration
- If you’re using the outdated
cordova-plugin-fcm, swap it for the better-maintainedcordova-plugin-fcm-with-dependecy-updatedwith this command:cordova plugin remove cordova-plugin-fcm && cordova plugin add cordova-plugin-fcm-with-dependecy-updated - Double-check that your
GoogleService-Info.plistis correctly added to your iOS project (drag it into Xcode and make sure it’s linked to your app target, with "Copy items if needed" checked). Confirm theBUNDLE_IDin this file matches your app’s exact Bundle ID.
- If you’re using the outdated
Permission Requests & Info.plist
- In your Ionic code, explicitly request push permissions once the platform is ready:
document.addEventListener("deviceready", function() { if (window.FCM) { FCM.requestPushPermissions().then(res => { console.log("Permission granted:", res); }).catch(err => { console.error("Permission denied:", err); }); } }, false); - Add these entries to your
Info.plist(via Xcode or the file directly) to comply with iOS privacy rules:NSRemoteNotificationUsageDescription: A clear message explaining why you need push access (e.g., "We send you updates about your orders and account activity")NSAlertUsageDescription: Same message as above (required for showing notification alerts)
- In your Ionic code, explicitly request push permissions once the platform is ready:
Xcode Project Settings
- Go to your project’s Signing & Capabilities tab:
- Add the Push Notifications capability
- Enable Background Modes and check the Remote notifications option (critical for background push delivery)
- Confirm your Code Signing Identity matches your Provisioning Profile (use Developer for testing, Distribution for production builds)
- Go to your project’s Signing & Capabilities tab:
Ionic 1 iOS Push Notification Full Implementation Guide
If you’re starting fresh with Ionic 1, follow these complete steps:
1. Base Setup
- Ensure your Ionic 1 project has the iOS platform added:
ionic platform add ios - Install the FCM plugin:
cordova plugin add cordova-plugin-fcm-with-dependecy-updated
2. Firebase & Apple Developer Config
- Create a Firebase project, add an iOS app with your exact Bundle ID, then download
GoogleService-Info.plist. Place it inplatforms/ios/[YourAppName]/and link it to your Xcode target. - In the Apple Developer Portal, enable Push Notifications for your App ID, generate APNs certificates, and upload them to Firebase’s Cloud Messaging settings.
- Generate a Provisioning Profile with Push permissions, download it, and install it in Xcode.
3. Ionic 1 Code Integration
Add this to your app.js run block to handle permissions, token retrieval, and notification listening:
.run(function($ionicPlatform) { $ionicPlatform.ready(function() { if (window.FCM) { // Request push permissions FCM.requestPushPermissions().then(function(permissions) { console.log("Push permissions granted:", permissions); // Get device FCM token (send this to your server for targeted pushes) FCM.getToken().then(function(token) { console.log("Device FCM Token:", token); // Example: $http.post("/api/save-token", { token: token }); }); }).catch(function(err) { console.error("Failed to get push permissions:", err); }); // Listen for incoming notifications FCM.onNotification(function(data) { console.log("Received notification:", data); if (data.wasTapped) { // Triggered when user taps a notification while app is in background alert("Notification tapped: " + data.title); } else { // Triggered when app is in foreground alert("New notification: " + data.title); } }); } }); })
4. Test the Push
- For development: Use Firebase Console’s Cloud Messaging tab to send a test message, select the "Development" environment, and paste your device’s FCM token.
- For production: Build an Ad Hoc or App Store version, use the production APNs certificate, and test with production tokens.
内容的提问来源于stack exchange,提问作者B.maiTi
相关产品推荐
相关产品推荐

