FirebaseFirestore 可以在 iOS 应用扩展中使用吗?



我正在尝试在 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

  • FirebaseFirestore (1.8.1(:
  • FirebaseFirestoreSwift (0.2(:

我确保在Firestore.firestore((之前调用FirebaseApp.configure((

我还将 -ObjC 添加到扩展目标的其他链接器标志中,以及扩展 Pods/Target\ Support\ Files/Pods*/.xcconfig 中的OTHER_LDFLAGS

如果 iOS 应用程序扩展不支持 Firestore,是否可以使用 Firestore REST 调用,因为身份验证似乎在扩展中工作?

解决了我自己的问题:

我将"其他链接器标志"从主目标复制到扩展目标。 在扩展目标的"其他链接器标志"中,我删除了以下内容:

$(inherited)
-framework "FirebaseMessaging"
-framework "protobuf"

这解决了问题。

然后,我将扩展目标的"其他链接器标志"更改为"$(继承(,这似乎也有效。

Firestore 似乎没有初始化并向 Firebase 注册(即使代码以某种方式链接,因为我能够在调试器中逐步完成它(

谷歌开发人员:如果

- (nullable id)instanceForProtocol:(Protocol *)protocol {

在找不到协议时记录了错误或抛出异常,而不仅仅是返回 nil

Firestore 未包含在扩展的"其他链接器标志"中。 这可能是由于我最初设置 Podfile 的方式

初始 pod 文件:

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

最新更新