Bạn có thể sử dụng đoạn mã sau
if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
// This will run if it is iOS6 or higher
return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else {
// This will run before iOS6 and you can use openUDID or other
// method to generate an identifier
}
Và bằng cách này bạn có thể duy trì các yêu cầu tối thiểu trước.
Mã nhận dạng này là duy nhất cho tất cả các ứng dụng từ một nhà cung cấp. Nếu bạn muốn định danh duy nhất cho thiết bị bạn cần sử dụng:
if (!NSClassFromString(@"ASIdentifierManager")) {
// This will run before iOS6 and you can use openUDID, per example...
return [OpenUDID value];
}
return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
Warning: Có một lỗi trên iOS6 rằng báo cáo "vô giá trị" nhận dạng nếu thiết bị đã được cập nhật "bằng đường hàng không" - More info
Nguồn
2012-09-26 14:23:18
bản sao có thể có của [UIDevice uniqueIdentifier không được chấp nhận - Cần làm gì bây giờ?] (Http://stackoverflow.com/questions/6993325/uidevice-uniqueidentifier-deprecated-what-to-do-now) –