Flutter集成Firebase在iOS模拟器运行失败问题求助
Hey there, let's work through these iOS compilation issues you're hitting with your Flutter + Firebase project step by step. I've dealt with similar headaches when working with older Firebase plugin versions, so here's how to resolve each error:
1. Fixing 'UIUserNotificationSettings' Missing Availability Markup
Xcode Error: 'UIUserNotificationSettings'未添加可用性标记,建议使用UserNotifications框架的UNNotificationSettings
This error pops up because UIUserNotificationSettings is a deprecated API starting from iOS 10, replaced by UNNotificationSettings from the UserNotifications framework. Here's how to fix it:
- Locate the file in your Xcode project where this error is thrown (it's likely in the
cloud_firestoreplugin's iOS source code, underPods/FirebaseMessagingor similar paths). - Add the availability markup above the problematic method/class:
@available(iOS, deprecated: 10.0, message: "Use UNNotificationSettings instead") - Alternatively, if you're open to updating your plugin version (since ^0.7.0+2 is quite outdated), upgrading to a newer
cloud_firestorerelease will likely resolve this issue automatically, as newer versions align with modern iOS SDK standards.
2. Fixing 'UIBackgroundFetchResult' Missing Availability Markup
Xcode Error: 'UIBackgroundFetchResult'未添加可用性标记
UIBackgroundFetchResult has had API changes across iOS versions, which triggers this availability warning. Here's the fix:
- Find the code block referencing
UIBackgroundFetchResultin your Xcode project (again, likely in Firebase-related plugin code). - Add the appropriate availability annotation. For example, if the code targets iOS 7.0+ but is deprecated in iOS 13.0:
@available(iOS, introduced: 7.0, deprecated: 13.0) - If updating the
cloud_firestoreplugin isn't an option immediately, this manual markup addition will suppress the error.
3. Resolving Implicit Conversion Warnings (NSUInteger ↔ int/UInt32)
Xcode Warning: 多处存在NSUInteger到int/UInt32的精度丢失隐式转换
These warnings happen because NSUInteger is an unsigned 64-bit type (on 64-bit systems), while int/UInt32 are smaller types, leading to potential precision loss. To fix this:
- Go to each warning location in Xcode.
- Replace the implicit conversion with an explicit cast. For example:
- If converting from
NSUIntegertoint:(int)yourNSUIntegerVariable - If converting from
NSUIntegertoUInt32:(UInt32)yourNSUIntegerVariable
- If converting from
- This makes the type conversion intentional and suppresses the warning.
General Troubleshooting Steps
Before diving into manual code edits, try these quick fixes to rule out caching or configuration issues:
- Run
flutter cleanin your project root to clear Flutter's build cache. - Navigate to your
iosdirectory, runpod deintegratefollowed bypod installto refresh your CocoaPods dependencies. - Verify your Xcode project's Deployment Target is set to at least iOS 9.0 (the minimum required for older
cloud_firestoreversions).
内容的提问来源于stack exchange,提问作者Uchenna F. Okoye

