Swift 编译器错误(Xcode):没有这样的模块“shared_preferences_ios” - Flutter

Tom*_*ard 3 xcode notifications dart flutter awesome-notifications

笔记

\n
    \n
  • 最近更新至 Xcode 版本 14.2 (14C18)
  • \n
  • Flutter 3.7.0 \xe2\x80\xa2 通道稳定
  • \n
\n

问题

\n

当运行我的 iOS 版 Flutter 应用程序时,出现以下错误:

\n
Xcode build done.                                           86.8s\nFailed to build iOS app\nCould not build the precompiled application for the device.\nSwift Compiler Error (Xcode): No such module \'shared_preferences_ios\'\n/Users/tomasward/Desktop/fredi_new/ios/Runner/AppDelegate.swift:3:7\n
Run Code Online (Sandbox Code Playgroud)\n

这是从这段代码派生出来的AppDelegate.swift:

\n
import UIKit\nimport Flutter\nimport awesome_notifications\nimport shared_preferences_ios //error here\n\n@UIApplicationMain\n@objc class AppDelegate: FlutterAppDelegate {\n  override func application(\n    _ application: UIApplication,\n    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n  ) -> Bool {\n    GeneratedPluginRegistrant.register(with: self)\n      \n      if #available(iOS 10.0, *) {\n           UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate\n          }\n         \n       application.registerForRemoteNotifications()\n      \n\n            SwiftAwesomeNotificationsPlugin.setPluginRegistrantCallback { registry in\n                SwiftAwesomeNotificationsPlugin.register(\n                  with: registry.registrar(forPlugin: "io.flutter.plugins.awesomenotifications.AwesomeNotificationsPlugin")!)\n                FLTSharedPreferencesPlugin.register(\n                  with: registry.registrar(forPlugin: "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin")!)\n            }\n    return super.application(application, didFinishLaunchingWithOptions: launchOptions)\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

此代码是awesome_notificationsios 插件设置的样板。看这里

\n

我尝试过一百万个解决方案

\n
    \n
  • 删除ios构建和运行flutter create .
  • \n
  • 运行pod install一百万次,删除podfile等
  • \n
\n

似乎没有一个解决方案是一致的。我正在寻找从事Flutter项目工作的人的通用解决方案,而不是本机 ios 项目。

\n

awesome_notifications如果与我一起工作的人能给我一些见解,那就太好了

\n

mso*_*wal 5

对于最新/当前版本,请执行以下操作

shared_preferences_ios用。。。来代替shared_preferences_foundation

与FLTSharedPreferencesPlugin​SharedPreferencesPlugin

因为这些是 flutter 内部最新的原生绑定,请参阅 PR。

AppDelegate.swift包含新更新解决方案的内容

import UIKit
import Flutter
import awesome_notifications
import shared_preferences_foundation //replace this here

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)

      if #available(iOS 10.0, *) {
          UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
      }

      application.registerForRemoteNotifications()

            SwiftAwesomeNotificationsPlugin.setPluginRegistrantCallback { registry in
                SwiftAwesomeNotificationsPlugin.register(
                  with: registry.registrar(forPlugin: "io.flutter.plugins.awesomenotifications.AwesomeNotificationsPlugin")!)
                SharedPreferencesPlugin.register( // replace here
                  with: registry.registrar(forPlugin: "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin")!)
            }
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
Run Code Online (Sandbox Code Playgroud)