3

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.

Jun Luo
  • 139
  • 1
  • 13

2 Answers2

3
 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.

Jun Luo
  • 139
  • 1
  • 13
  • 1
    Using the UUID will likely get your app **rejected** during an AppStore review. Here are some [alternatives](https://possiblemobile.com/2013/04/unique-identifiers/) – Sixto Saez Jun 02 '16 at 14:03
3

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

Crashlytics.sharedInstance().setUserIdentifier("12345")
Crashlytics.sharedInstance().setUserEmail("mail@domain.com")
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

Bishal Ghimire
  • 2,580
  • 22
  • 37
  • I integrated Crashlytics for my application! but failed to set value for setUserIdentifier('12345'). where do i find this UserIdentifier value? – kiran Aug 05 '18 at 00:20
  • @kiran : AppDelegate is the place to do ur SDKs setup. Add the above code in ur didFinishLaunchingWithOptions method – Bishal Ghimire Aug 06 '18 at 01:03
  • my question is where to find the value of userIdentifier value. This 12345 value -> where to find? – kiran Aug 06 '18 at 01:24
  • @kiran : that is up to your application-specific question, each app handles how it stores user information. The "12345" in this case is just an example code. In your application, you should replace it with the actual user id that has logged into your app. – Bishal Ghimire Aug 07 '18 at 02:04
  • @kiran Use your user's userId from backend API. – Neeraj Joshi Jan 07 '19 at 09:36