有没有一种使用Swift语言获取IOS设备真实Wi-Fi MAC地址的方法?非常感谢提供代码片段!
有没有一种使用Swift语言获取IOS设备真实Wi-Fi MAC地址的方法?非常感谢提供代码片段!
当您在iOS 7及以上版本中请求设备MAC地址时,您将始终收到相同的响应:02:00:00:00:00:00。这是由Apple出于隐私问题而做出的决定。
在iOS 7及更高版本中,如果您要求iOS设备的MAC地址,系统将返回值02:00:00:00:00:00。如果您需要标识设备,请改用UIDevice的identifierForVendor属性。(需要为自己的广告目的使用标识符的应用程序应考虑改用ASIdentifierManager的advertisingIdentifier属性。)
如果您需要唯一标识iOS设备,Apple建议改用UDID
。在Swift
中可以使用以下代码:
UIDevice.currentDevice().identifierForVendor
如果您想使用字符串,请使用以下代码:
UIDevice.currentDevice().identifierForVendor.UUIDString
这里有一篇关于UDID的好文章。
UIDevice.current.identifierForVendor.uuidString
- Raphael由于某些安全问题,您无法获取MAC地址。相反,您可以使用UUID来唯一标识设备。
对于Swift 4.2
UIDevice().identifierForVendor?.uuidString ?? ""
针对Objective-C
[[[UIDevice currentDevice] identifierForVendor] UUIDString]
针对iOS 15,请执行以下操作:
UIDevice.current.identifierForVendor?.uuidString