http标头请求中的UDID iphone

时间:2012-09-12 13:11:03

标签: iphone http header

可以让我的iPhone自动发送所有http请求标头中的UDID吗?

1 个答案:

答案 0 :(得分:1)

您可以创建自己的UUID,如果需要,可以添加到标题中。将UUID保存在首选项中。

也许在- (BOOL)application:didFinishLaunchingWithOptions:

中执行此操作
if (![[NSUserDefaults standardUserDefaults] stringForKey:@"deviceID"]) {
    CFUUIDRef uuid = CFUUIDCreate(NULL);
    NSString *uuidString = (__bridge_transfer NSString *) CFUUIDCreateString(NULL, uuid);
    [[NSUserDefaults standardUserDefaults] setValue:uuidString forKey:@"deviceID"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    CFRelease(uuid);
}

然后,您可以将标头添加到NSMutableURLRequest

NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];

[request setValue:[[NSUserDefaults standardUserDefaults] stringForKey:@"deviceID"]
 forHTTPHeaderField:@"Device-ID"];