【问题标题】:CIFilter with CIQRCodeGenerator cause crash带有 CIQRCodeGenerator 的 CIFilter 导致崩溃
【发布时间】:2020-08-17 18:25:33
【问题描述】:

我正在尝试使用以下代码生成二维码:

DispatchQueue.main.async {
    let image = generateQRCode(from: qrCodeString)
}

func generateQRCode(from string: String?) -> UIImage? {

    if let data = string?.data(using: .utf8, allowLossyConversion: false) {
        if let filter = CIFilter(name: "CIQRCodeGenerator") {

            filter.setValue(data, forKey: "inputMessage")
            let transform = CGAffineTransform(scaleX: 5, y: 5)

            if let output = filter.outputImage?.transformed(by: transform) {
                return UIImage(ciImage: output)
            }
        }
    }
    return nil
}

此代码适用于大多数设备/iOS 版本

但是 firebase 给我带来了很多设备崩溃:iPhone 11、XR。 iOS 13.4.0

Crashed: com.apple.main-thread
0  CocoaDebug                     0x1023a0adc perform_rebinding_with_section + 332
1  CocoaDebug                     0x1023a087c rebind_symbols_for_image + 416
2  libdyld.dylib                  0x1999c3f4c invocation function for block in dyld3::AllImages::runImageCallbacks(dyld3::Array<dyld3::LoadedImage> const&) + 244
3  libdyld.dylib                  0x1999c3768 dyld3::AllImages::runImageCallbacks(dyld3::Array<dyld3::LoadedImage> const&) + 160
4  libdyld.dylib                  0x1999c8dd8 dyld3::AllImages::loadImage(Diagnostics&, unsigned int, dyld3::closure::DlopenClosure const*, bool, bool, bool, bool) + 580
5  libdyld.dylib                  0x1999c89ec dyld3::AllImages::dlopen(Diagnostics&, char const*, bool, bool, bool, bool, bool, void const*) + 868
6  libdyld.dylib                  0x1999ca434 dyld3::dlopen_internal(char const*, int, void*) + 364
7  libdyld.dylib                  0x1999bd6c0 dlopen + 116
8  CoreFoundation                 0x199bcf5c8 _CFBundleDlfcnLoadBundle + 156
9  CoreFoundation                 0x199af1eac _CFBundleLoadExecutableAndReturnError + 372
10 Foundation                     0x199ec27a8 -[NSBundle loadAndReturnError:] + 316
11 CoreImage                      0x19b479bcc invocation function for block in register_more_builtins(void (NSString*) block_pointer) + 804
12 libdispatch.dylib              0x19986833c _dispatch_client_callout + 20
13 libdispatch.dylib              0x199869a68 _dispatch_once_callout + 32
14 CoreImage                      0x19b476318 register_more_builtins(void (NSString*) block_pointer) + 304
15 CoreImage                      0x19b476b40 classNameIsSystemFilter(NSString*) + 112
16 CoreImage                      0x19b476dbc +[CIFilter(CIFilterRegistryPrivate) filterWithName:setDefaults:] + 396
17 MYApp                          0x100656598 QRCodeViewController.generateQRCode(from:) + 4370490776 (<compiler-generated>:4370490776)
18 MYApp                          0x1006563a4 QRCodeViewController.viewDidLoad() + 28 (QRCodeViewController.swift:28)
19 MYApp                          0x10065642c @objc QRCodeViewController.viewDidLoad() + 4370490412 (<compiler-generated>:4370490412)
20 UIKitCore                      0x19d6a236c -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 104
21 UIKitCore                      0x19d6a6f20 -[UIViewController loadViewIfRequired] + 952
22 UIKitCore                      0x19d6a730c -[UIViewController view] + 32
23 UIKitCore                      0x19d602fa4 -[UINavigationController _startCustomTransition:] + 1148
24 UIKitCore                      0x19d617478 -[UINavigationController _startDeferredTransitionIfNeeded:] + 692
25 UIKitCore                      0x19d618818 -[UINavigationController __viewWillLayoutSubviews] + 176
26 UIKitCore                      0x19d5fb4fc -[UILayoutContainerView layoutSubviews] + 228
27 UIKitCore                      0x19e1de6a0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2168
28 QuartzCore                     0x1a08314a0 -[CALayer layoutSublayers] + 292
29 QuartzCore                     0x1a08318e0 CA::Layer::layout_if_needed(CA::Transaction*) + 472
30 QuartzCore                     0x1a0843dc4 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 144
31 QuartzCore                     0x1a0788884 CA::Context::commit_transaction(CA::Transaction*, double) + 304
32 QuartzCore                     0x1a07b33d0 CA::Transaction::commit() + 656
33 QuartzCore                     0x1a07b3fc8 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 96
34 CoreFoundation                 0x199b42c54 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
35 CoreFoundation                 0x199b3d8e4 __CFRunLoopDoObservers + 420
36 CoreFoundation                 0x199b3dd84 __CFRunLoopRun + 1020
37 CoreFoundation                 0x199b3d660 CFRunLoopRunSpecific + 480
38 GraphicsServices               0x1a3f4e604 GSEventRunModal + 164
39 UIKitCore                      0x19dd1215c UIApplicationMain + 1944
40 MYApp                          0x100518e54 main + 4369190484 (<compiler-generated>:4369190484)
41 libdyld.dylib                  0x1999b91ec start + 4

我尝试了几种不同的编码,我尝试在主线程或背景中进行,但总是没有结果。

看起来整个类 CIFilter 会导致崩溃!!

【问题讨论】:

  • 这很奇怪。从堆栈跟踪看来,Core Image 找不到相应的过滤器类,然后尝试从库中动态加载某些东西......? oO 在iOS 13 中,您可以尝试import CoreImage.CIFilterBuildins 并使用let filter = CIFilter.qrCodeGenerator() 初始化过滤器。这应该不能在运行时失败...... ????
  • 你好@FrankSchlegel,谢谢你的回答。我无法导入 CoreImage.CIFilterBuildins 但导入 CoreImage.CIFilter。而且我无法使用 CIFilter.qrCodeGenerator() 初始化过滤器
  • 是的,CoreImage.CIFilterBuiltins 很遗憾仅在 iOS 13 中可用...
  • 哦,我打错了:CIFilterBuiltinst,而不是 d
  • @FrankSchlegel 不幸的是它不起作用。也许是另一个想法?

标签: ios swift crash core-image cifilter


【解决方案1】:

我想出了如何解决它。问题是第三方CocoaDebug!我移除了吊舱,我再也没有崩溃了!谢谢!

【讨论】:

    猜你喜欢
    • 2020-09-27
    • 2018-11-27
    • 2012-12-19
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    • 1970-01-01
    • 2022-07-09
    相关资源
    最近更新 更多