where to implement setUserIdentifier function from crashlytics in swift

1.4k views Asked by At

I am new to swift. I am now trying to implement crashlytics in to my app. I have followed the tutorial to implement it for basic report but I want to implement userID so that I know who has problem using my app. I have checked online and found setUserIdentifier function but I have no idea where to implement this function. Do I need to call this function in every page or in app delegate.swift? Please give me an example on how to implement this one function.

Thank you very much.

2

There are 2 answers

1
Jun Luo On BEST ANSWER
 let phoneID = UIDevice.currentDevice().identifierForVendor.UUIDString
 Fabric.with([Crashlytics()])
 Crashlytics.sharedInstance().setUserIdentifier(phoneID)

I used this to solve the problem and get the phone id.

5
Bishal Ghimire On

I would strongly discourage the @Jun-Luo 's approach of using UUUID.

Crashlytics.sharedInstance().setUserIdentifier("12345")
Crashlytics.sharedInstance().setUserEmail("[email protected]")
Crashlytics.sharedInstance().setUserName("AppUserName")

You can use any one of above to track the user. But its better to secure user privacy, hence all we need as a developer is a ID which we can easily tack back with our server side access.

Code Example

https://docs.fabric.io/apple/crashlytics/enhanced-reports.html