QuincyKit/PLCrashReporter: provide description *before* the crash

时光总嘲笑我的痴心妄想 提交于 2019-11-29 12:02:53

No, but the feature was proposed over 2 years ago and there's a patch.

I'd actually prefer a version that allowed logging the contents of a ring buffer (which you could efficiently log messages to!), which seems potentially much more useful.

Seva Alekseyev

Found a limited workaround. I use a shared memory block with a name that's derived from bundle ID to store the context string. The block is cleared on proper shutdown. Then I override -crashReportDescription in my Quincy delegate so that it provides the shared memory contents, if any, as description. It is only nonempty if the last app shutdown was a crash.

There are obviously flaws with this approach. If they, say, restart the device between the crash and the next app startup, the shared memory info is lost.

EDIT: in the first version of the design, I used a private, named UIPasteboard instead of shared memory. That turned out to be quite a performance hit. Shared memory is orders of magnitude faster.

EDIT2: but then they broke shared memory in iOS 7, so UIPasteboard is back. Bummer.

EDIT3: found another approach, less elegant but it works in iOS 7. I store my context string in a plain static memory block. I place a custom crash handler within PLCrashReporter with [[PLCrashReporter sharedReporter] setCrashCallbacks:]. In the handler, I write out said context (if any) to a file. On app startup, I read said file, and provide the contents (if any) in -crashReportDescription. Go away, UIPasteboard.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!