如何在iOS8中使用IOKit获取设备的序列号,因为IOPlatformSerialNumber给出nil值 [英] How to get serial number of a device using IOKit in iOS8 as IOPlatformSerialNumber giving nil value

查看:1361
本文介绍了如何在iOS8中使用IOKit获取设备的序列号,因为IOPlatformSerialNumber给出nil值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在iOS8中使用 IOKit 获取设备的序列号?我使用 UIDevice + serialNumber ,我可以在iOS6和7中获得序列号。在iOS8中, platformSerialNumber 的值将在以下行中 nil

I was wondered to know how to get serial number of a device using IOKit in iOS8? I used UIDevice+serialNumber and I am able to get serial number in iOS6 and7. In iOS8 value of platformSerialNumber is coming nil in the following line:

CFTypeRef platformSerialNumber = IORegistryEntryCreateCFProperty(platformExpertDevice,CFSTR("IOPlatformSerialNumber"), kCFAllocatorDefault, 0);

我正在使用: https://gist.github.com/0xced/566994

注意:我的应用程序不会转到应用程序商店,它用于内部。所以我正在寻找一些永远不会改变的具体事物,无论是字符串还是整数

Note:My app will not go to app store, its for inhouse. So I am looking for something more concrete that will never change, either String or integer

推荐答案

从iOS 8开始,硬件信息,如序列号,受到保护。如果要检索此值,则必须使用私有权利对应用进行签名。我不确定是否可以在企业应用程序中使用私有权利,它们肯定不能用于App Store应用程序,但这个问题用越狱标记,所以我将为此提供解决方案。

Starting in iOS 8, hardware information, such as the serial number, is protected. If you want to retrieve this value, you must sign your app with private entitlements. I'm not sure if it's possible to use private entitlements in enterprise apps, and they certainly can't be used for App Store apps, but this question is tagged with jailbreak so I'll provide a solution for that.

如果您希望序列号跟踪公司拥有的设备,我建议您利用Apple的移动设备管理(MDM)等服务。这使您可以访问大量有关设备的信息,并允许您远程管理它们。

If you want the serial number to track devices your company owns, I'd recommend taking advantage of a service like Apple's mobile device management (MDM). This gives you access to a large amount of information about devices, and allows you to manage them remotely.

如果您只是寻找永远不会改变的标识符其他目的,我建议使用设备的UDID。我能够在没有权利的情况下在我的设备上获得此功能,但这可能是由于我的手机被越狱了。其他人告诉我,事实上,权利是必需的。有关这方面的更多信息,请访问 iPhoneDevWiki

If you're simply looking for an identifier that will never change for other purposes, I'd recommend using the device's UDID instead. I was able to get this on my device without entitlements, however that may be due to my phone being jailbroken. I've been told by others that entitlements are, in fact, required. More information about this can be found on the iPhoneDevWiki.

代码:

- (NSString *)udid
{
    void *gestalt = dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_GLOBAL | RTLD_LAZY);
    CFStringRef (*MGCopyAnswer)(CFStringRef) = (CFStringRef (*)(CFStringRef))(dlsym(gestalt, "MGCopyAnswer"));
    return CFBridgingRelease(MGCopyAnswer(CFSTR("UniqueDeviceID")));
}

权利:

<key>com.apple.private.MobileGestalt.AllowedProtectedKeys</key>
<array>
    <string>UniqueDeviceID</string>
</array>

这篇关于如何在iOS8中使用IOKit获取设备的序列号,因为IOPlatformSerialNumber给出nil值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆