identifierForVendor和iOS6

Rya*_*yan 10 xcode itunes objective-c ios

identifierForVendor要求iOS6的,所以如果我的应用程序目前支持iOS4的,所以我不能使用它,因为我的更新应该总能满足我的应用程序以前分钟.需求?

Nak*_*aka 28

你可以用这个:

NSString *udid;

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
    udid = [UIDevice currentDevice].identifierForVendor.UUIDString;
else
    udid = [UIDevice currentDevice].uniqueIdentifier;
Run Code Online (Sandbox Code Playgroud)

使用预处理器代码:

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
Run Code Online (Sandbox Code Playgroud)

  • 而不是比较版本,检查选择器:f([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) (11认同)

Las*_*zlo 7

您不需要预处理器宏,您应该检查它是否响应,如下所示:

if ([[UIDevice currentDevice]respondsToSelector:@selector(identifierForVendor)]) {
    return [UIDevice currentDevice].identifierForVendor.UUIDString;
}else{
    // return [UIDevice currentDevice]. uniqueIdentifier
    return [[UIDevice currentDevice] performSelector:@selector(uniqueIdentifier)];
}
Run Code Online (Sandbox Code Playgroud)