ios 获取手机序列号
时间: 2023-09-23 22:04:08 浏览: 99
可以通过以下代码获取iOS设备的序列号:
```objc
#import <UIKit/UIKit.h>
#import <sys/utsname.h>
NSString* deviceSerialNumber() {
struct utsname systemInfo;
uname(&systemInfo);
NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G (A1203)";
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G (A1241/A1324)";
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS (A1303/A1325)";
if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4 (A1332)";
if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4 (A1332)";
if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4 (A1349)";
if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S (A1387/A1431)";
if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5 (A1428)";
if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5 (A1429/A1442)";
if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c (A1456/A1532)";
if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c (A1507/A1516/A1526/A1529)";
if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s (A1453/A1533)";
if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s (A1457/A1518/A1528/A1530)";
if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus (A1522/A1524)";
if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6 (A1549/A1586)";
if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone 6s (A1633/A1688/A1691/A1700)";
if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus (A1634/A1687/A1690/A1699)";
if ([platform isEqualToString:@"iPhone8,4"]) return @"iPhone SE (A1662/A1723/A1724)";
if ([platform isEqualToString:@"iPhone9,1"]) return @"iPhone 7 (A1660/A1779/A1780)";
if ([platform isEqualToString:@"iPhone9,3"]) return @"iPhone 7 (A1778)";
if ([platform isEqualToString:@"iPhone9,2"]) return @"iPhone 7 Plus (A1661/A1785/A1786)";
if ([platform isEqualToString:@"iPhone9,4"]) return @"iPhone 7 Plus (A1784)";
if ([platform isEqualToString:@"iPhone10,1"] || [platform isEqualToString:@"iPhone10,4"]) return @"iPhone 8 (A1863/A1906)";
if ([platform isEqualToString:@"iPhone10,2"] || [platform isEqualToString:@"iPhone10,5"]) return @"iPhone 8 Plus (A1864/A1898/A1899)";
if ([platform isEqualToString:@"iPhone10,3"] || [platform isEqualToString:@"iPhone10,6"]) return @"iPhone X (A1865/A1901)";
if ([platform isEqualToString:@"iPhone11,2"]) return @"iPhone XS (A2097/A2098)";
if ([platform isEqualToString:@"iPhone11,4"] || [platform isEqualToString:@"iPhone11,6"]) return @"iPhone XS Max (A1921/A2103)";
if ([platform isEqualToString:@"iPhone11,8"]) return @"iPhone XR (A1984/A2105)";
if ([platform isEqualToString:@"iPhone12,1"]) return @"iPhone 11 (A2111/A2223/A2221)";
if ([platform isEqualToString:@"iPhone12,3"]) return @"iPhone 11 Pro (A2215/A2160/A2217)";
if ([platform isEqualToString:@"iPhone12,5"]) return @"iPhone 11 Pro Max (A2218/A2161/A2220)";
if ([platform isEqualToString:@"iPhone12,8"]) return @"iPhone SE 2nd Gen (A2275/A2296/A2298)";
if ([platform isEqualToString:@"iPhone13,1"]) return @"iPhone 12 mini (A2176/A2398/A2399/A2400)";
if ([platform isEqualToString:@"iPhone13,2"]) return @"iPhone 12 (A2402/A2403/A2404/A2405)";
if ([platform isEqualToString:@"iPhone13,3"]) return @"iPhone 12 Pro (A2341/A2406/A2407/A2408)";
if ([platform isEqualToString:@"iPhone13,4"]) return @"iPhone 12 Pro Max (A2342/A2410/A2411/A2412)";
return nil;
}
NSString* getDeviceSerialNumber() {
UIDevice *device = [UIDevice currentDevice];
NSString *deviceSerialNumber = nil;
if ([device respondsToSelector:@selector(identifierForVendor)]) {
deviceSerialNumber = [[device identifierForVendor] UUIDString];
} else {
deviceSerialNumber = (NSString*)CFBridgingRelease(CFUUIDCreateString(NULL, CFUUIDCreate(NULL)));
}
return deviceSerialNumber;
}
```
其中,`getDeviceSerialNumber` 返回的是设备的唯一标识符,可以用作设备的序列号。
阅读全文