-
Notifications
You must be signed in to change notification settings - Fork 4
How to search Crashlytics iOS events by user barcode
SimplyE and Open eBooks report error and informational events to Firebase / Crashlytics. Sometimes it is useful to search the database by user ID / barcode to extract all the events and logs associated with that user activity. This document explains how to do that.
When a user signs in and an error condition happens, we attach a one-way hash of the barcode to the event we send to Firebase. This makes it impossible for us to derive the original value from the hashed value logged in Firebase. However, if we are in possession of the barcode we can hash it the same way we hash it inside the app, and then search Firebase for that hashed value.
Open Xcode and add the following code to a Playground:
extension String {
public func md5() -> Data {
let messageData = self.data(using:.utf8)!
var digestData = Data(count: Int(CC_MD5_DIGEST_LENGTH))
_ = digestData.withUnsafeMutableBytes { digestBytes in
messageData.withUnsafeBytes { messageBytes in
CC_MD5(messageBytes.baseAddress, CC_LONG(messageData.count),
digestBytes.bindMemory(to: UInt8.self).baseAddress)
}
}
return digestData
}
public func md5hex() -> String {
return md5().map { String(format: "%02hhx", $0) }.joined()
}
}
Incidentally, this is the same code that the app uses to hash the barcode before logging it to Firebase.
Then, simply call the md5hex
function on the barcode string, as such:
"23305012991242".md5hex()
The value you obtain can then be plugged into the "Search by User ID" button in the Crashlytics home page:

That's it!