gpt4 book ai didi

ios - Swift 崩溃 libobjc.A.dylib objc_msgSend

转载 作者:搜寻专家 更新时间:2023-10-30 23:15:12 24 4
gpt4 key购买 nike

我使用 crashlytics 来获取我在 AppStore 中的应用程序的崩溃情况。有些用户遇到崩溃,我似乎无法在我的机器上重现(少数通过 TestFlight 测试我的应用程序的 friend 也没有)。这是来自 Fabric 的日志:

Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x181d09bdc objc_msgSend + 28
1 Foundation 0x18304be20 __NSThreadPerformPerform + 340
2 CoreFoundation 0x182640efc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
3 CoreFoundation 0x182640990 __CFRunLoopDoSources0 + 540
4 CoreFoundation 0x18263e690 __CFRunLoopRun + 724
5 CoreFoundation 0x18256d680 CFRunLoopRunSpecific + 384
6 GraphicsServices 0x183a7c088 GSEventRunModal + 180
7 UIKit 0x1873e4d90 UIApplicationMain + 204
8 <App Name> 0x1000b2f0c main (AppDelegate.swift:14)
9 libdispatch.dylib 0x18210e8b8 (Missing)

我似乎无法理解这意味着什么,并搜索了其他问题以寻求帮助,但似乎找不到答案。我也很快联系了 Crashlytics 团队,他们告诉我以下内容:

It sounds like the source of this crash is some sort of out of memory crash. This causing Crashlytics to close before it finishes writing, resulting in this in your crash report.

为了查明崩溃的根源,有什么好的调试方法吗?感谢您的帮助!

编辑:在 crashlytics 的崩溃报告中添加了 Threads 的屏幕截图,以防有人想从那里获取一些信息: enter image description here

Thread : com.apple.NSURLConnectionLoader
0 libsystem_kernel.dylib 0x1823354bc mach_msg_trap + 8
1 libsystem_kernel.dylib 0x182335338 mach_msg + 72
2 CoreFoundation 0x182764ac0 __CFRunLoopServiceMachPort + 196
3 CoreFoundation 0x1827627c4 __CFRunLoopRun + 1032
4 CoreFoundation 0x182691680 CFRunLoopRunSpecific + 384
5 CFNetwork 0x182e01434 +[NSURLConnection(Loader) _resourceLoadLoop:] + 412
6 Foundation 0x18316fc40 __NSThread__start__ + 1000
7 libsystem_pthread.dylib 0x182417b28 _pthread_body + 156
8 libsystem_pthread.dylib 0x182417a8c _pthread_body + 154
9 libsystem_pthread.dylib 0x182415028 thread_start + 4

Thread : AVAudioSession Notify Thread
0 libsystem_kernel.dylib 0x1823354bc mach_msg_trap + 8
1 libsystem_kernel.dylib 0x182335338 mach_msg + 72
2 CoreFoundation 0x182764ac0 __CFRunLoopServiceMachPort + 196
3 CoreFoundation 0x1827627c4 __CFRunLoopRun + 1032
4 CoreFoundation 0x182691680 CFRunLoopRunSpecific + 384
5 libAVFAudio.dylib 0x188959834 GenericRunLoopThread::Entry(void*) + 164
6 libAVFAudio.dylib 0x18892e3a8 CAPThread::Entry(CAPThread*) + 84
7 libsystem_pthread.dylib 0x182417b28 _pthread_body + 156
8 libsystem_pthread.dylib 0x182417a8c _pthread_body + 154
9 libsystem_pthread.dylib 0x182415028 thread_start + 4

编辑 2:我正在使用所有 Swift 代码,我将消息转发给选择器的方式如下:

NSTimer.scheduledTimerWithTimeInterval(0.02, target: self, selector: Selector("updateProgressCircle"), userInfo: nil, repeats: true)

func updateProgressCircle() {
// Do something
}

问题是我无法在本地重现任何崩溃。只有用户会面临这种情况。我以类似的方式调用选择器。

最佳答案

objc_msgSend 当您尝试将消息转发到选择器(使用旧的 Objective-C 转发消息)时发生崩溃。这可以通过目标操作、通知、协议(protocol)声明、计时器、执行选择器或涉及传入函数选择器语法的任何其他函数产生:即:"doSomethingWithThis:"

我可以从您的崩溃日志中看到您的应用程序中有快速组件(至少是 AppDelegate)。与 Obj-C 组件不同,Swift 组件不兼容开箱即用的 Obj-C 转发消息系统。

我的直觉是,您的代码中有一个符合协议(protocol)的 swift 对象,被添加为目标/通知观察者,或者以某种方式期望其函数之一被转发消息调用。我建议你通过你的类(class),看看是否是这种情况。找到罪魁祸首后,您可以通过将 @objc 附加到需要消息的函数来轻松修复此错误。

即:如果您的函数在 swift 类中被调用(例如,注册了一个通知):

func yourFunction() {
//your code
}

调用它:

@objc func yourFunction() {
//your code
}

虽然希望不大,但希望对您有所帮助!

关于ios - Swift 崩溃 libobjc.A.dylib objc_msgSend,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35836230/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com