我想知道使用我的应用程序的iPhone的序列号.我在下面写了代码.
- (NSString*)getSerialNumber
{
CFTypeRef serialNumberAsCFString;
io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
if (platformExpert)
{
serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
}
IOObjectRelease(platformExpert);
NSString *serial = [[NSString alloc] initWithFormat:@"%@",serialNumberAsCFString];
NSLog(@"serail no==>%@",serialNumberAsCFString);
NSLog(@"serail no==>%@",serial);
}
Run Code Online (Sandbox Code Playgroud)
为什么我的序列号仍然错误?
小智 5
你应该改变的参数2 IORegistryEntryCreateCFProperty,从CFSTR (kIOPlatformUUIDKey)到CFSTR (kIOPlatformSerialNumberKey).然后您将获得正确的序列号(长度为11个字符).
您正在链接 IOKit 框架吗?
尝试一下
id getValue(NSString *iosearch);
Run Code Online (Sandbox Code Playgroud)
功能,可在
http://blogs.oreilly.com/iphone/2008/08/retriving-device-information.html
您还可以使用 UIDevice 类来检索其他有用的信息例如,您可以执行以下操作:
NSString *id = [[UIDevice currentDevice] uniqueIdentifier];
Run Code Online (Sandbox Code Playgroud)
其他有用的属性如下:
name
systemName
systemVersion
model
localizedModel
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17537 次 |
| 最近记录: |