ANRDetector - is a simple framework for detecting cases when application is not responsive (Main thread is blocked). Using a timer it measures how much time was spend on a test operation. It notifies about changes within delegate pattern.
- Drag-and-drop Framework/ANRDetector.framework to your project. Make sure it is present under ‘Link binary with libraries” section in Build Phases of your project.
- Import ANRDetector in your class
import ANRDetector
- Implement delegate methods (if needed)
extension YourClass: ANRDetectorDelegate {
func didDetectANR() {
print("⛔️ ANR DETECTED")
}
func didBackToNormal(anrDuration: TimeInterval) {
print("✅ Back to normal. ANR duration: \(anrDuration) sec.")
}
}
Problems/difficulties I’ve met:
- The ANR duration time calculated is not very precise - this could be improved.
- Preparing universal framework that supports x86_64 / arm64 (lipo). I wish there were simple checkbox for this.