xcode 配置应用程序时发生 Firebase 错误 - 无法识别的选择器发送到类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42169907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:47:06  来源:igfitidea点击:

Firebase error while configuring app - unrecognized selector sent to class

iosxcodefirebase

提问by Pat Needham

I'm using Firebase in an iOS app and have two separate Firebase projects, one for production and one for development. My two .plist files are GoogleService-Info.plistand GoogleService-Info-Dev.plist, which I have been able to select based on a flag set in Targets -> Build Settings -> Other Swift Flags.

我在 iOS 应用程序中使用 Firebase,并且有两个单独的 Firebase 项目,一个用于生产,一个用于开发。我的两个 .plist 文件是GoogleService-Info.plistand GoogleService-Info-Dev.plist,我可以根据在 Targets -> Build Settings -> Other Swift Flags 中设置的标志进行选择。

Inside AppDelegate didFinishLaunchingWithOptions:

在 AppDelegate 中didFinishLaunchingWithOptions

#if DEBUG
    let buildFor = "DEV"
#else
    let buildFor = "PROD"
#endif
let firebasePlistFileName = buildFor == "DEV" ? "GoogleService-Info-Dev" : "GoogleService-Info"
let firebaseOptions = FIROptions(contentsOfFile: NSBundle.mainBundle().pathForResource(firebasePlistFileName, ofType: "plist"))
FIRApp.configureWithOptions(firebaseOptions) // line causing new Firebase error

This has been working fine up until today, when I had a problem with another Cocoapod project. I think it started happening when I cleaned the Xcode project or deleted Derived Data folder:

直到今天,当我在另一个 Cocoapod 项目中遇到问题时,这一直运行良好。我认为它在我清理 Xcode 项目或删除派生数据文件夹时开始发生:

dyld: Library not loaded: @rpath/OtherPod.framework/OtherPod
  Referenced from:
  /Users/me/Library/Developer/CoreSimulator/Devices/12345678-E1C4-480F-B1D9-C10823DEA810/data/Containers/Bundle/Application/AE7B6EB0-43AB-CCCC-BBBB-AAAA71BF/MyApp.app/MyApp
  Reason: image not found

I eventually resolved that by choosing my app under Targets -> General -> Linked Frameworks and Libraries, then added all of the choices inside the Workspacefolder (7 other pod projects) and set those ones I added as optional. Ever since then, I've been facing the error described in the title of this post:

我最终通过在 Targets -> General -> Linked Frameworks and Libraries 下选择我的应用程序解决了这个问题,然后在Workspace文件夹中添加了所有选项(7 个其他 pod 项目)并将我添加的那些设置为可选。从那时起,我一直面临这篇文章标题中描述的错误:

2017-02-10 17:19:29.660 MyApp[12639:182433] +[NSData gtm_dataByGzippingData:error:]: unrecognized selector sent to class 0x10a0442e8
2017-02-10 17:19:29.680 MyApp[12639:182433] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSData gtm_dataByGzippingData:error:]: unrecognized selector sent to class 0x10a0442e8'
*** First throw call stack:
(
  0   CoreFoundation                      0x0000000109d88d4b __exceptionPreprocess + 171
  1   libobjc.A.dylib                     0x00000001097f121e objc_exception_throw + 48
  2   CoreFoundation                      0x0000000109df8e44 +[NSObject(NSObject) doesNotRecognizeSelector:] + 132
  3   CoreFoundation                      0x0000000109d0e005 ___forwarding___ + 1013
  4   CoreFoundation                      0x0000000109d0db88 _CF_forwarding_prep_0 + 120
  5   MyApp                               0x0000000102d73c9d -[FIRNetwork postURL:payload:queue:usingBackgroundSession:completionHandler:] + 331
  6   MyApp                               0x0000000102d70e72 -[FIRClearcutLogger sendNextPendingRequestWithCompletionHandler:] + 570
  7   MyApp                               0x0000000102d70918 -[FIRClearcutLogger sendLogsWithCompletionHandler:] + 447
  8   libdispatch.dylib                   0x000000010a6ab978 _dispatch_call_block_and_release + 12
  9   libdispatch.dylib                   0x000000010a6d50cd _dispatch_client_callout + 8
  10  libdispatch.dylib                   0x000000010a6b2e17 _dispatch_queue_serial_drain + 236
  11  libdispatch.dylib                   0x000000010a6b3b4b _dispatch_queue_invoke + 1073
  12  libdispatch.dylib                   0x000000010a6b402b _dispatch_queue_override_invoke + 683
  13  libdispatch.dylib                   0x000000010a6b6385 _dispatch_root_queue_drain + 720
  14  libdispatch.dylib                   0x000000010a6b6059 _dispatch_worker_thread3 + 123
  15  libsystem_pthread.dylib             0x000000010aa3a712 _pthread_wqthread + 1299
  16  libsystem_pthread.dylib             0x000000010aa3a1ed start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

I have tried a lot of different fixes, including adding to the Link Binary with Libraries, adding to the Other Linker Flags, and none of them have worked.

我尝试了很多不同的修复方法,包括使用 Libraries添加到Link Binary添加到 Other Linker Flags,但都没有奏效。

What could the unrecognized selector possibly be, and how would I change/remove it? Could this issue be due to the earlier one I was facing (library not loaded)?

无法识别的选择器可能是什么,我将如何更改/删除它?这个问题可能是由于我面临的较早一个问题(库未加载)?

For clarification, when the unrecognized selector sent to classerror happens, the Xcode debug navigator is focused on Thread 7, with the FIRApp.configureWithOptions(firebaseOptions)line being highlighted.

为了澄清起见,当unrecognized selector sent to class错误发生时,Xcode 调试导航器将重点放在 Thread 7 上,并FIRApp.configureWithOptions(firebaseOptions)突出显示该行。

Update

更新

I found a temporary fix by reverting to a previous git commit (cloned my repository into a separate directory), then replacing the majority of the project contents from that old commit with the current error-producing copy, including the App-Namefolder within root directory, App-Name.xcodeproj, and App-Name.xcworkspace. I only tested on the simulator (iPhone 7 running iOS 10.2), and that worked. I then successfully submitted a build to iTunes Connect and was able to run that build on my device (iPhone 5c with 10.2.1), but after deleting that and attempting to run a build from Xcode, I got the same error again. However, the error did notoccur while running on the simulator. This is in contrast to the initial error scenario as it occurred on both physical device and simulator.

我通过恢复到以前的 git 提交(将我的存储库克隆到一个单独的目录中)找到了一个临时修复,然后用当前产生错误的副本替换旧提交中的大部分项目内容,包括根目录中的App-Name文件夹目录、应用名称.xcodeproj 和应用名称.xcworkspace。我只在模拟器(运行 iOS 10.2 的 iPhone 7)上进行了测试,结果奏效了。然后我成功地向 iTunes Connect 提交了一个构建,并且能够在我的设备(iPhone 5c 和 10.2.1)上运行该构建,但是在删除它并尝试从 Xcode 运行构建后,我再次遇到了同样的错误。然而,错误并没有在模拟器上运行时发生。这与初始错误场景相反,因为它同时发生在物理设备和模拟器上。

This made me remember that the stack trace I initially posted was that of running the app on the simulator. Running it on the device produced less output, specifically the content after *** First throw call stack:is only (0x1d01cdf7 0x1c27f077 0x1d022467 0x1d020579 0x1cf453d8 0x31ff3f 0x31d653 0x31d05d 0x1c57d57 0x1c63e63 0x1c5b205 0x1c64391 0x1c65d9f 0x1c65ba7 0x1c877937 0x1c877490)instead of the more descriptive output with file/function names.

这让我想起我最初发布的堆栈跟踪是在模拟器上运行应用程序的堆栈跟踪。在设备上运行它会产生较少的输出,特别是之后的内容*** First throw call stack:只是,(0x1d01cdf7 0x1c27f077 0x1d022467 0x1d020579 0x1cf453d8 0x31ff3f 0x31d653 0x31d05d 0x1c57d57 0x1c63e63 0x1c5b205 0x1c64391 0x1c65d9f 0x1c65ba7 0x1c877937 0x1c877490)而不是带有文件/函数名称的更具描述性的输出。

回答by COVID19

Earlier, I have faced the same issue, I fixed the issue by reinstalling pod.

早些时候,我遇到了同样的问题,我通过重新安装pod.

Please refer to the below-mentioned steps to resolve the issue.

请参考以下步骤来解决问题。

Please make sure that you have added Add two-parameter in Other Linker Flags.

请确保您已添加添加两个参数 Other Linker Flags.

$(inherited)
-ObjC

Cocoapods:

可可豆:

Just install cocoa-pods again in the project. Please refer below command for remove and install pods.

只需在项目中再次安装 cocoa-pods 即可。请参阅以下命令以删除和安装 pod。

Remove all Framework from project using below command.

使用以下命令从项目中删除所有框架。

pod deintegrate
pod clean

- Install framework using below pod command

- 使用下面的 pod 命令安装框架

pod install

Manual:

手动的:

If you have added frameworkManual in the project then remove it and add it into the project again.

如果您framework在项目中添加了手册,则将其删除并再次添加到项目中。

Issue:

问题:

You have faced reference issue in your project (frameworknot found at Specific Directory).

您在项目中遇到了参考问题(framework未在特定目录中找到)。

Hit the Clean and Build project. Everything worked as expected

点击 Clean and Build 项目。一切都按预期进行

回答by Paul Beusterien

Make sure GTMNSData+zlib.m from the GoogleToolboxForMac pod is still being built and linked into your app.

确保来自 GoogleToolboxForMac pod 的 GTMNSData+zlib.m 仍在构建并链接到您的应用程序中。

enter image description here

在此处输入图片说明

Make sure that -ObjC and -framework GoogleToolboxForMac is in the Link log:

确保 -ObjC 和 -framework GoogleToolboxForMac 在链接日志中:

enter image description here

在此处输入图片说明

回答by martin meincke

To anyone experiencing this problem, while trying to add the firebase frameworks manually. I had the same issue, which was caused by having different versions of firebase. I tried to add additional frameworks as the readme suggested, but experienced the above mentioned error.

对于在尝试手动添加 firebase 框架时遇到此问题的任何人。我遇到了同样的问题,这是由不同版本的 firebase 引起的。我尝试按照自述文件的建议添加其他框架,但遇到了上述错误。

I resolved this by removing all the firebase frameworks from the project and build phases. Downloaded the newest version, and re-added all frameworks to the project, and the problem was resolved.

我通过从项目和构建阶段中删除所有 firebase 框架解决了这个问题。下载最新版本,将所有框架重新添加到项目中,问题解决。