ios - 如何消除这些与使用 SwiftUI 相关的常见 Firebase 警告?
问题描述
我在我的 SwiftUI/Combine 应用程序中使用 Firebase,我注意到一些我想解决的警告。他们没有破坏事情,但我想解决它们。我在使用具有最新 Swift 包依赖项的 Xcode 12.4 时收到这些警告:GoogleUtilities 7.2.2 和 Firebase 7.7.0。
这是控制台中出现的第一个警告:
[GoogleUtilities/AppDelegateSwizzler][I-SWZ001014] App Delegate does not conform to UIApplicationDelegate protocol.
作为参考,这是我配置 Firebase 的方式:
import SwiftUI
import Firebase
@main
struct MyApp: App {
@StateObject var authState = AuthState()
init() {
FirebaseApp.configure()
}
var body: some Scene {
WindowGroup {
RootView()
.environmentObject(authState)
}
}
}
这是第二个警告,在我使用.navigationBarTitle
修饰符设置导航栏标题后出现。
[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x280c8cfa0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x109219b60]-(6)-[_UIModernBarButton:0x109218760'Fullres'] (active)>",
"<NSLayoutConstraint:0x280c8cff0 'CB_Trailing_Trailing' _UIModernBarButton:0x109218760'Fullres'.trailing <= _UIButtonBarButton:0x109217100.trailing (active)>",
"<NSLayoutConstraint:0x280c8dd60 'UINav_static_button_horiz_position' _UIModernBarButton:0x109219b60.leading == UILayoutGuide:0x2816bcfc0'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x280c8ddb0 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x109217100]-(0)-[UILayoutGuide:0x2816bcee0'UINavigationBarItemContentLayoutGuide'] (active)>",
"<NSLayoutConstraint:0x280c88f00 'UINavItemContentGuide-trailing' UILayoutGuide:0x2816bcee0'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x109214320.trailing (active)>",
"<NSLayoutConstraint:0x280c8e530 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x109214320.width == 0 (active)>",
"<NSLayoutConstraint:0x280c892c0 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x2816bcfc0'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UINavigationBarContentView:0x109214320 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x280c8cfa0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x109219b60]-(6)-[_UIModernBarButton:0x109218760'Fullres'] (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
有没有人试图解决这些警告?
解决方案
第一条消息是由于 Firebase 试图找到一个AppDelegate
,但由于您的应用遵循新的 SwiftUI 应用生命周期,它没有一个。
您可以通过添加AppDelegate
如下内容来消除此警告:
import SwiftUI
import Firebase
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
return true
}
}
@main
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
@StateObject var authState = AuthState()
init() {
FirebaseApp.configure()
}
var body: some Scene {
WindowGroup {
RootView()
.environmentObject(authState)
}
}
}
有关更多详细信息,请参阅我关于该主题的文章。
作为旁注,我们正在研究初始化 Firebase SDK 的其他方法(因为 swizzling 有其挑战) - 请参阅关于类似 GitHub 问题的评论。
至于第二个警告,这与 Firebase 无关。如果您搜索 StackOverflow,您会发现许多其他人也遇到了这个问题。这个问题看起来非常相似,并且有一个您可能想尝试的公认答案。
推荐阅读
- php - PHP:switch语句的问题(错误的返回)
- php - 编辑帖子时如何在管理员而不是帖子所属的用户时存储相同的ID
- spring - 线程“主”java.lang.NoSuchMethodError 中的异常:org.slf4j.impl.StaticLoggerBinder.getSingleton()
- angular - 如何从应用程序中删除操作栏?
- python - Jinja2 将 WTF-Form 获取/导入到 Basic.html(包含在其他每个 html 页面中)
- java - 记录器文件的动态压缩
- python-3.x - 如何将 python 连接到 Microsoft 商店并下载应用程序?
- python - NN的DNA数据输入,一种热编码
- go - go run 命令没有提供足够的信息来调试
- javascript - 机器人加入公会的所有语音频道并播放文件