可以让我的iPhone自动发送所有http请求标头中的UDID吗?
答案 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"];