Flutter [firebase_messaging] IOS 构建错误

Bar*_*gor 5 ios firebase swift flutter firebase-cloud-messaging

我在使用 Firebase Messaging ( https://pub.dev/packages/firebase_messaging )时遇到问题。将其添加到项目后,我无法在 IOS 中构建。

我试过:

flutter clean
flutter precache    
pod deintegrate
pod setup
pod install
Run Code Online (Sandbox Code Playgroud)

尝试:删除 Podfile.lock

编辑/删除 WorkspaceSettings.xcsettings

将构建系统更改为 Legacy

我在实际项目中也遇到同样的问题。我创建了空白项目,构建 ios 并在模拟器上运行。添加 FirebaseMessaging 后出现此构建错误。尝试了我发短信的方法,但对我不起作用。错误:

In file included from /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:9:
    /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Headers/Public/Firebase/Firebase.h:81:10: warning: "FirebaseAnalytics.framework is not
    included in your target. Please add the FirebaseAnalytics dependency to your project to ensure Messaging works as intended." [-W#warnings]
            #warning "FirebaseAnalytics.framework is not included in your target. Please add the \
             ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:190:43: error: expected a
    type
    - (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {
                                              ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:274:42: warning:
    'UIUserNotificationSettings' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNNotificationSettings
    [-Wdeprecated-declarations]
        didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
                                             ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIUserNotificationSettings.h:44:12: note: 'UIUserNotificationSettings' has been explicitly marked deprecated here
    @interface UIUserNotificationSettings : NSObject
               ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:285:53: error: nullability
    specifier 'nonnull' conflicts with existing specifier 'nullable'
        didReceiveRegistrationToken:(nonnull NSString *)fcmToken {
                                                        ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:290:24: error: expected a
    type
        didReceiveMessage:(FIRMessagingRemoteMessage *)remoteMessage {
                           ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:117:7: warning:
    'UIUserNotificationType' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNAuthorizationOptions
    [-Wdeprecated-declarations]
          UIUserNotificationType notificationTypes = 0;
          ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIUserNotificationSettings.h:17:32: note: 'UIUserNotificationType' has been explicitly marked deprecated here
    typedef NS_OPTIONS(NSUInteger, UIUserNotificationType) {
                                   ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:119:30: warning:
    'UIUserNotificationTypeSound' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNAuthorizationOptions
    [-Wdeprecated-declarations]
            notificationTypes |= UIUserNotificationTypeSound;
                                 ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIUserNotificationSettings.h:17:32: note: 'UIUserNotificationType' has been explicitly marked deprecated here
    typedef NS_OPTIONS(NSUInteger, UIUserNotificationType) {
                                   ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:122:30: warning:
    'UIUserNotificationTypeAlert' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNAuthorizationOptions
    [-Wdeprecated-declarations]
            notificationTypes |= UIUserNotificationTypeAlert;
                                 ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIUserNotificationSettings.h:17:32: note: 'UIUserNotificationType' has been explicitly marked deprecated here
    typedef NS_OPTIONS(NSUInteger, UIUserNotificationType) {
                                   ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:125:30: warning:
    'UIUserNotificationTypeBadge' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNAuthorizationOptions
    [-Wdeprecated-declarations]
            notificationTypes |= UIUserNotificationTypeBadge;
                                 ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIUserNotificationSettings.h:17:32: note: 'UIUserNotificationType' has been explicitly marked deprecated here
    typedef NS_OPTIONS(NSUInteger, UIUserNotificationType) {
                                   ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:128:7: warning:
    'UIUserNotificationSettings' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNNotificationSettings
    [-Wdeprecated-declarations]
          UIUserNotificationSettings *settings =
          ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIUserNotificationSettings.h:44:12: note: 'UIUserNotificationSettings' has been explicitly marked deprecated here
    @interface UIUserNotificationSettings : NSObject
               ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:129:39: warning:
    'UIUserNotificationSettings' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNNotificationSettings
    [-Wdeprecated-declarations]
              [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];
                                          ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIUserNotificationSettings.h:44:12: note: 'UIUserNotificationSettings' has been explicitly marked deprecated here
    @interface UIUserNotificationSettings : NSObject
               ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:130:42: warning:
    'registerUserNotificationSettings:' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's
    -[UNUserNotificationCenter requestAuthorizationWithOptions:completionHandler:] and -[UNUserNotificationCenter setNotificationCategories:]
    [-Wdeprecated-declarations]
          [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
                                             ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIApplication.h:250:1: note: 'registerUserNotificationSettings:' has been explicitly marked deprecated here
    - (void)registerUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings API_DEPRECATED("Use UserNotifications Framework's
    -[UNUserNotificationCenter requestAuthorizationWithOptions:completionHandler:] and -[UNUserNotificationCenter setNotificationCategories:]",
    ios(8.0, 10.0)) API_UNAVAILABLE(tvos);
    ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:136:30: error: property
    'shouldEstablishDirectChannel' not found on object of type 'FIRMessaging *'
        [FIRMessaging messaging].shouldEstablishDirectChannel = true;
                                 ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:155:21: warning:
    'FIRInstanceID' is deprecated: FIRInstanceID is deprecated, please use FIRInstallations for installation identifier handling and use
    FIRMessaging for FCM registration token handling. [-Wdeprecated-declarations]
        [[FIRInstanceID instanceID]
                        ^
    In module 'FirebaseInstanceID' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Headers/Public/Firebase/Firebase.h:74:
    /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/FirebaseInstanceID/Firebase/InstanceID/Public/FIRInstanceID.h:190:1: note: 'FIRInstanceID'
    has been explicitly marked deprecated here
    __deprecated_msg("FIRInstanceID is deprecated, please use FIRInstallations for installation "
    ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    In module 'Foundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIKit.h:8:
    In module 'CoreFoundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/Foundation.f
    ramework/Headers/Foundation.h:6:
    In module 'Darwin' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/CoreFoundati
    on.framework/Headers/CoreFoundation.h:16:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/include/sys/cdefs.h:200:48: note:
    expanded from macro '__deprecated_msg'
            #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                          ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:156:33: warning:
    'FIRInstanceIDResult' is deprecated: FIRInstanceIDResult is deprecated, please use FIRInstallations for app instance identifier handling and
    use FIRMessaging for FCM registration token handling. [-Wdeprecated-declarations]
            instanceIDWithHandler:^(FIRInstanceIDResult *_Nullable instanceIDResult,
                                    ^
    In module 'FirebaseInstanceID' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Headers/Public/Firebase/Firebase.h:74:
    /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/FirebaseInstanceID/Firebase/InstanceID/Public/FIRInstanceID.h:153:1: note:
    'FIRInstanceIDResult' has been explicitly marked deprecated here
    __deprecated_msg("FIRInstanceIDResult is deprecated, please use FIRInstallations "
    ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    In module 'Foundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIKit.h:8:
    In module 'CoreFoundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/Foundation.f
    ramework/Headers/Foundation.h:6:
    In module 'Darwin' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/CoreFoundati
    on.framework/Headers/CoreFoundation.h:16:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/include/sys/cdefs.h:200:48: note:
    expanded from macro '__deprecated_msg'
            #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                          ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:156:9: warning:
    'instanceIDWithHandler:' is deprecated: Use `Installations.installationID(completion:)` to get the app instance identifier instead. Use
    `Messaging.token(completion:)` to get FCM registration token instead. [-Wdeprecated-declarations]
            instanceIDWithHandler:^(FIRInstanceIDResult *_Nullable instanceIDResult,
            ^
    In module 'FirebaseInstanceID' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Headers/Public/Firebase/Firebase.h:74:
    /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/FirebaseInstanceID/Firebase/InstanceID/Public/FIRInstanceID.h:215:5: note:
    'instanceIDWithHandler:' has been explicitly marked deprecated here
        __deprecated_msg("Use `Installations.installationID(completion:)` to get the app instance "
        ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    In module 'Foundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIKit.h:8:
    In module 'CoreFoundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/Foundation.f
    ramework/Headers/Foundation.h:6:
    In module 'Darwin' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/CoreFoundati
    on.framework/Headers/CoreFoundation.h:16:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/include/sys/cdefs.h:200:48: note:
    expanded from macro '__deprecated_msg'
            #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                          ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:166:21: warning:
    'FIRInstanceID' is deprecated: FIRInstanceID is deprecated, please use FIRInstallations for installation identifier handling and use
    FIRMessaging for FCM registration token handling. [-Wdeprecated-declarations]
        [[FIRInstanceID instanceID] deleteIDWithHandler:^void(NSError *_Nullable error) {
                        ^
    In module 'FirebaseInstanceID' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Headers/Public/Firebase/Firebase.h:74:
    /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/FirebaseInstanceID/Firebase/InstanceID/Public/FIRInstanceID.h:190:1: note: 'FIRInstanceID'
    has been explicitly marked deprecated here
    __deprecated_msg("FIRInstanceID is deprecated, please use FIRInstallations for installation "
    ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    In module 'Foundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIKit.h:8:
    In module 'CoreFoundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/Foundation.f
    ramework/Headers/Foundation.h:6:
    In module 'Darwin' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/CoreFoundati
    on.framework/Headers/CoreFoundation.h:16:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/include/sys/cdefs.h:200:48: note:
    expanded from macro '__deprecated_msg'
            #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                          ^
    /Users/mac/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-7.0.3/ios/Classes/FLTFirebaseMessagingPlugin.m:166:33: warning:
    'deleteIDWithHandler:' is deprecated: Use `Installations.delete(completion:)` instead. Also check `Messaging.deleteData(completion:)`if you
    want to delete FCM registration token. [-Wdeprecated-declarations]
        [[FIRInstanceID instanceID] deleteIDWithHandler:^void(NSError *_Nullable error) {
                                    ^
    In module 'FirebaseInstanceID' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Headers/Public/Firebase/Firebase.h:74:
    /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/FirebaseInstanceID/Firebase/InstanceID/Public/FIRInstanceID.h:321:33: note:
    'deleteIDWithHandler:' has been explicitly marked deprecated here
                                    __deprecated_msg("Use `Installations.delete(completion:)` instead. "
                                    ^
    In module 'UIKit' imported from /Users/mac/Desktop/Flutter Apps/iyifiyatt/ios/Pods/Target Support
    Files/firebase_messaging/firebase_messaging-prefix.pch:2:
    In module 'Foundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/UIKit.framew
    ork/Headers/UIKit.h:8:
    In module 'CoreFoundation' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/Foundation.f
    ramework/Headers/Foundation.h:6:
    In module 'Darwin' imported from
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhone

Bar*_*gor 8

解决了!

它通过运行此命令解决:

rm -rf Pods  
rm -rf Podfile.lock  
rm -rf ~/.pub-cache/hosted/pub.dartlang.org/  
flutter clean  
flutter pub get  
pod repo update  
flutter build ios
Run Code Online (Sandbox Code Playgroud)