在友盟里注册App时需要获取UDID,但友盟只给出OC版本。
以下是自己写的Swift版本:
class func GetUDID() {
let deviceSelector = Selector("openUDIDString")
guard
let cls = NSClassFromString("UMANUtil"),
let deviceID = (cls as? NSObjectProtocol)?.performSelector(deviceSelector).takeUnretainedValue() as? String,
let jsonData = try? NSJSONSerialization.dataWithJSONObject(["oid": deviceID], options: NSJSONWritingOptions.PrettyPrinted)
else {
NSLog("UMengUDIDGetter: Can't get UDID.")
return
}
NSLog("%@", String(data: jsonData, encoding: NSUTF8StringEncoding)!)
}