有没有一种方法可以验证iPhone设备ID? 我想要能够通过HTTP请求接受iPhone用户提交的设备ID并验证它们是否绑定到合法设备。
有没有一种方式可以验证 iPhone 设备 ID?我想通过 HTTP 请求接收 iPhone 用户提交的设备 ID,并验证其是否绑定到合法设备。有没有一种方法可以验证iPhone设备ID? 我想要能够通过HTTP请求接受iPhone用户提交的设备ID并验证它们是否绑定到合法设备。
有没有一种方式可以验证 iPhone 设备 ID?我想通过 HTTP 请求接收 iPhone 用户提交的设备 ID,并验证其是否绑定到合法设备。针对Martin Gorton的问题,第三方库不能信任UIDevice uniqueIdentifier- 使用Objective C方法交换很容易欺骗它。
方法交换可以交换一个类(UIDevice)的两个选择器(uniqueIdentifier和spoofUniqueIdentifier)。交换后,调用UIDevice uniqueIdentifier的后续调用将返回欺骗的UDID。这对于测试没有有效UDID的UDID键入库可能会有所帮助。
以下是来自http://marccodes.posterous.com/method-swizzling-uidevice-to-spoof-udid的一些示例代码:
#import <objc/runtime.h>
// swap a class's instance method selectors, we do this to overload existing methods in category declarations
void swizzleMethodsForClass(Class c, SEL origMethodSel, SEL newMethodSel)
{
NSLog(@"swizzling %@ instance methods: %@ -> %@", NSStringFromClass(c),
NSStringFromSelector(origMethodSel), NSStringFromSelector(newMethodSel));
Method origMethod = class_getInstanceMethod(c, origMethodSel);
Method newMethod = class_getInstanceMethod(c, newMethodSel);
// check if method is inherited from superclass
if(class_addMethod(c, origMethodSel, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(c, newMethodSel, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
// exchange un-subclassed method
else
method_exchangeImplementations(origMethod, newMethod);
}
@interface UIDevice (SpoofUDID)
@end
#define UDID_TO_SPOOF @"e0101010d38bde8e6740011211af315301010223"
@implementation UIDevice (SpoofUDID)
// swizzle this instance method for UIDevice class
- (NSString *) spoofUniqueIdentifier
{
static NSString *spoofUDID = UDID_TO_SPOOF;
NSLog(@"spoofing %@ instead of %@", spoofUDID, [[UIDevice currentDevice]
spoofUniqueIdentifier]);
return spoofUDID;
}
@end
// call this from your app delegate
- (void) initUDID
{
NSString *UDID = [[UIDevice currentDevice] uniqueIdentifier];
NSLog(@"this is my old udid: %@", UDID);
swizzleMethodsForClass([UIDevice class], @selector(uniqueIdentifier), @selector(spoofUniqueIdentifier));
NSString *UDID2 = [[UIDevice currentDevice] uniqueIdentifier];
NSLog(@"this is my new udid: %@", UDID2);
}
目前为止,没有苹果文档或规范指定此字符串的布局。
只有苹果知道哪些 UDID 是真实的,哪些是虚假的。
一个合理的猜测是它们长度为 40 个字符,由字母数字字符组成。(a-f0-9)
正则表达式模式:
[a-z0-9]{40}
如果您直接使用[[UIDevice currentDevice] uniqueIdentifier]
来获取设备ID,而不是提示用户输入,则没有理由认为它不是合法的设备ID。