我正在尝试在Swift iOS应用扩展中使用Firestore
Firestore在主应用程序中工作正常,但是Firestore.firestore()在应用程序扩展中返回nil
当我进入调试器时,看到Firestore在未注册的组件中
主应用程序:
- (nullable id)instanceForProtocol:(Protocol *)protocol {
self FIRComponentContainer * 0x28359e1f0 0x000000028359e1f0
_app FIRApp * 0x28359e250 0x000000028359e250
_components __NSDictionaryM * 5 key/value pairs 0x0000000283bdc2c0
[0] (null) @"FIRInstanceIDInstanceProvider" : (no summary)
[1] (null) @"FSTFirestoreMultiDBProvider" : (no summary)
[2] (null) @"FIRAnalyticsInterop" : (no summary)
[3] (null) @"FIRAuthInterop" : (no summary)
[4] (null) @"FIRMessagingInstanceProvider" : (no summary)
_cachedInstances __NSDictionaryM * 3 key/value pairs 0x0000000283bdc2e0
_eagerProtocolsToInstantiate NSMutableArray * nil 0x0000000000000000
protocol Protocol * 0x1056645e8 0x00000001056645e8
protocolName __NSCFString * @"FSTFirestoreMultiDBProvider" 0x000000028359b3c0
cachedInstance id 0x0 0x0000000000000000
creationBlock FIRComponentCreationBlock 0x000000010507eb40
扩展名:
self FIRComponentContainer * 0x11fd07ae0 0x000000011fd07ae0
NSObject NSObject
_app FIRApp * 0x11fd0dd50 0x000000011fd0dd50
_components __NSDictionaryM * 1 key/value pair 0x000000011fd2a150
[0] (null) @"FIRAuthInterop" : (no summary)
_cachedInstances __NSDictionaryM * 1 key/value pair 0x000000011fd2ac20
_eagerProtocolsToInstantiate NSMutableArray * nil 0x0000000000000000
protocol Protocol * 0x1050ce0e8 0x00000001050ce0e8
protocolName __NSCFString * @"FSTFirestoreMultiDBProvider" 0x000000011fe0e540
cachedInstance id 0x0 0x0000000000000000
creationBlock FIRComponentCreationBlock (null)
来自Podfile.lock
我确保在Firestore.firestore()之前调用FirebaseApp.configure()
我还向扩展目标的其他链接器标志以及扩展Pods / Target \ Support \ Files / Pods * /。xcconfig中的OTHER_LDFLAGS添加了-ObjC
如果iOS应用程序扩展中不支持Firestore,由于Auth似乎在扩展中有效,是否可以使用Firestore REST调用?
解决了我自己的问题:
我已将“其他链接器标志”从主目标复制到扩展目标。在扩展目标的“其他链接器标志”中,我删除了以下内容:
$(inherited)
-framework "FirebaseMessaging"
-framework "protobuf"
此问题已解决。
然后我将扩展目标的“其他链接器标志”更改为“ $(继承),并且看起来同样有效。
似乎Firestore并未在Firebase上初始化和注册(即使代码以某种方式链接在一起,因为我能够在调试器中逐步完成它)
Google开发人员:如果更容易发现,则>]
- (nullable id)instanceForProtocol:(Protocol *)protocol {
记录错误或在找不到协议时抛出异常,而不仅仅是返回nil
Firestore未包含在扩展的“其他链接器标志”中。这可能是由于我最初设置Podfile的方式
初始Podfile:
target 'XXX' do use_frameworks! pod 'Firebase/Core' pod 'Firebase/Messaging' pod 'Firebase/Firestore' pod 'FirebaseFirestoreSwift' pod 'Firebase/Auth' target 'XXXExtension' do inherit! :search_paths end end
新Podfile:
target 'XXX' do
use_frameworks!
pod 'Firebase/Core'
pod 'Firebase/Messaging'
pod 'Firebase/Firestore'
pod 'FirebaseFirestoreSwift'
pod 'Firebase/Auth'
end
target 'XXXExtension' do
use_frameworks!
pod 'Firebase/Core'
pod 'Firebase/Firestore'
pod 'FirebaseFirestoreSwift'
pod 'Firebase/Auth'
end