kstenerud / KSCrash

The Ultimate iOS Crash Reporter
MIT License
4.23k stars 705 forks source link

State tracking based - isa swizzle #492

Open naftaly opened 3 months ago

naftaly commented 3 months ago

If we can, we try and swizzle App and Scene delegates.


This is a proposal. What you have already works just fine, but it could be a bit more precise.


Lifecycle delegate and notifications don't happen in the same stack, the stack unwinds after the delegate calls.

run loop cycle 1: Application -> Delegate run loop cycle 2: Application -> Notification

Due to this, it's very hard for a system to receive lifecycle events before the app it is being installed in. This can lead to mismatched user perception (foreground when the app is actually background). That mismatch leads to wrongly categorizing issues reported by the system.

To fix this, we need to swizzle app a scene delegates. This allows us to receive delegate callbacks before anyone else and correctly record the state of the app before the app has a chance to run any code in those transitions and possibly cause a reliability event.


The swizzle is the same kind of swizzling used in KVC as described here.

naftaly commented 3 months ago

@GLinnik21 @bamx23 for review, low pri.

GLinnik21 commented 2 months ago

@naftaly I noticed that there are conflicts in this pull request. Do you still plan to merge it?

naftaly commented 2 months ago

@naftaly I noticed that there are conflicts in this pull request. Do you still plan to merge it?

I don’t have time in the near future, but I think it’s an improvement to KS so if you want maybe you can commandeer and move it forward?

GLinnik21 commented 14 hours ago

@naftaly My apologies for the very delayed response. I've been quite busy lately and have also been focusing on preparing version 2.0. Given that it's been two months, this PR likely has even more conflicts now, which will only worsen over time. Perhaps we should revisit this feature after the 2.0 release? When you have time, it would be great if you could take another look and possibly rebase it. You're more familiar with the initial implementation, so your drive on this would be valuable. Let me know your thoughts on timing and next steps, considering the current state of the PR.​​​​​​​​​​​​​​​​

naftaly commented 10 hours ago

@GLinnik21 No issues in the delay, there's really no rush. I look forward to v2.0 being released and hopefully merged into larger toolsets that use it. We can revisit in the future. Ping me when you get around to planning for the next versions and we can discuss.