How to get unique id in iOS device?

后端 未结 6 1024
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 02:42

I have used mac address to identify iOS devices in server side. When run my application with iOS 7 unable to retrieve the correct mac address. Alternately i used

         


        
相关标签:
6条回答
  • 2020-11-27 03:03

    For Swift 5

    let deviceId = UIDevice.current.identifierForVendor?.uuidString
    
    0 讨论(0)
  • 2020-11-27 03:04

    You can no longer get a unique ID per device. identifierForVendor is the best you're going to get. Apple has systematically disabled identifying a specific device so that users' IDs can't be passed around by marketers.

    To get the identifier ID as a string, you can use

    let deviceId = UIDevice.current.identifierForVendor?.uuidString
    

    UPDATE

    If you want a universal ID then you have the option to use advertisingIdentifier. However, if the user has limited ad tracking in their device settings then this value will simply return all zeroes.

    import AdSupport
    
    let identifierManager = ASIdentifierManager.shared()
    if identifierManager.isAdvertisingTrackingEnabled {
        let deviceId = identifierManager.advertisingIdentifier.uuidString
    }
    

    N.B. Apple recommends that this code only be used by companies building advertisement frameworks, rather than the app developers themselves. If you use this within your code for non-ad-related purposes then prepare to have your app rejected.

    0 讨论(0)
  • 2020-11-27 03:16

    The best way to get the device id is identifierForVendor

    UIDevice *device = [UIDevice currentDevice];
    
    NSString  *currentDeviceId = [[device identifierForVendor]UUIDString];
    

    UPDATE

    For Swift 4.1 use

    UIDevice.current.identifierForVendor?.uuidString
    
    0 讨论(0)
  • 2020-11-27 03:19

    Getting device ID in

    Swift 3

    let device_id = UIDevice.currentDevice().identifierForVendor?.UUIDString
    

    Swift 4:

    let device_id = UIDevice.current.identifierForVendor!.uuidString
    
    0 讨论(0)
  • 2020-11-27 03:21

    Getting Device Id in Swift 3.x

    let deviceId = UIDevice.current.identifierForVendor?.uuidString
    
    0 讨论(0)
  • 2020-11-27 03:23

    You can use this lib: https://github.com/fabiocaccamo/FCUUID

    Please look on the table in the Persistence section. uuidForDevice will cover the most of needed cases and it is the best replacement to udid from old versions of iOS.

    Examples in Readme are in Objective-C but it works with Swift too. I have used it since Swift first release until now (Swift 4.1).

    0 讨论(0)
提交回复
热议问题