I have an iOS application written in Swift 2 in Xcode 8.2.1, that's built for iOS 10.2.
I've had a number of crash reports from TestFlight and despite symbolication, none of the crash logs show any program state besides the stack-traces (no argument values, no locals, no heap objects, etc).
...but inside those functions I can see code which is likely to fail (e.g. a forced unwrap) but the crash log isn't telling me where or why it's failing.
When debugging in Xcode, I can use fatalError(message: String)
where I can put my own message like "functionFoo returned nil"
or "variable bar == \"" + bar + "\""
, except when deployed using TestFlight or the App Store the fatalError
will be hit and the program terminates, but the message
value is not saved to the crash log, making it pointless.
In other environments, like C#/.NET and Java I can simply throw new SomeExceptionType("my message")
and all information is available in whatever global catch(Exception)
handler I have.
How can I achieve the same goal in iOS / Swift?
Maybe this can help you
import os
let osLogger = Logger(subsystem: yourBundleIdentifier, category: yourCategory)
osLogger.log(level: .debug, "\(yourCategoryName): \(message)")
Use a third party SDK for tracking crashes, such as Crashlytics (Firebase) or Sentry. You can also send a custom error to these platforms. Also they provide great statistics for all crashes/errors inside your app.
This one is more for a debug configuration (suitable for QA testing). Write a class for logging your event into a file inside of your documents directory. Create a simple ViewController that can open/export this file (DEBUG mode only). Cover all essential places in your code with logs and deliver the build to your QA, so they can attach a detailed steps for reproducing error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With