Reputation: 1457
I am looking to retrieve the crash logs in iPhone programmatically. Under iOS 10 and above, the list of logs can be found here :
Settings --> Privacy -->Analytics --> Analytics Data-->logfiles.json
Is it possible to access the log files programmatically. I am basically looking to get all the files that are found in the data section.Not just the files related to my app.
Note : I am not looking here for Appstore approval.
Upvotes: 9
Views: 2185
Reputation: 1248
Apple has updated to add this feature and now you can get them with import MetricKit
by on start initializing MetricKitManager()
. I am able to post the crash reports to my server by handling the didReceive
methods (see below). When I tested this the app had to be installed on my device for a little while (maybe an hour) before the Metric Kit became active and started receiving the crash reports as formatted base64 strings on launch of the app after the previous crash.
Note that crashes caught by xcode are not received by Metric Kit and crashes on the simulator are not received by Metric Kit, so you must launch from the app from your device and crash to test.
@available(iOS 14.0, *)
class MetricKitManager: NSObject, MXMetricManagerSubscriber {
public override init() {
super.init()
let metricManager = MXMetricManager.shared
metricManager.add(self)
}
func receiveReports() {
let shared = MXMetricManager.shared
shared.add(self)
}
func pauseReports() {
let shared = MXMetricManager.shared
shared.remove(self)
}
func didReceive(_ payloads: [MXMetricPayload]) {
var attachments: [String] = []
for payload in payloads {
let attachment = payload.jsonRepresentation().base64EncodedString()
attachments.append(attachment)
SubmitFeedback(eid: Employee.eid ?? "", message: attachment)
}
}
func didReceive(_ payloads: [MXDiagnosticPayload]) {
var attachments: [String] = []
for payload in payloads {
let attachment = payload.jsonRepresentation().base64EncodedString()
attachments.append(attachment)
SubmitFeedback(eid: Employee.eid ?? "", message: attachment)
}
}
}
Upvotes: 1
Reputation: 153
While Fabric/Crashlytics is nice, it does not support watchOS.
If you need watchOS support and more flexibility in regards to where you send the reports, check out KSCrash @ https://github.com/kstenerud/KSCrash
Upvotes: 0
Reputation: 15339
There is no public or private API to collect the crash reports iOS generates. On Jailbroken devices you should be able to go to the file system folder where iOS stores them and collect them directly from there. (You would need to find this folder as I don't know the exact location right now, but it is probably similar to where macOS stores them)
Upvotes: 2
Reputation: 535
You can collection this log via Fabric -such as Crashlytic and Answer ..
Upvotes: 0