StackOverflow和其他地方有很多关于如何清除Mac隔离属性的信息.在我的情况下,我想设置它.这是为了测试我的应用程序是否已正确签名,以便用户在下载后可以获得"Untrusted Developer"警告.
我的应用程序特别大(我们从大型文件下载站点分发,而不是商店)并且不方便上传和下载来测试它.过去一周,我与代码签名进行了一些争夺,所以这个测试对我很重要.
一旦文件具有隔离属性,我就会看到如何更改它以获取值:
0002 = downloaded but never opened (this is the one that causes the warning) 0022 = app aborted by user from the warning dialogue (you hit 'cancel' in the dialogue) 0062 = app opened (at least) once (you hit 'open' in the dialogue)
但我不知道如何首先给它这个属性.
这个代码并不难,但你需要FSRef来做,不推荐使用它.也就是说,它仍然适用于10.9.您必须与CoreServices链接.
int main(int argc, const char * argv[]) { @autoreleasepool { if (argc != 2) { printf("quarantine <path>\n"); exit(1); } NSString *path = @(argv[1]); OSStatus result; FSRef pathRef; result = FSPathMakeRef((UInt8*)[path UTF8String], &pathRef, 0); if (result != noErr) { NSLog(@"Error making ref (%d): %s", result, GetMacOSStatusCommentString(result)); exit(result); } NSDictionary *quarantineProperties = @{(__bridge id)kLSQuarantineTypeKey: (__bridge id)kLSQuarantineTypeOtherDownload}; result = LSSetItemAttribute(&pathRef, kLSRolesAll, kLSItemQuarantineProperties, (__bridge CFTypeRef)quarantineProperties); if (result != noErr) { NSLog(@"Error setting attribute (%d): %s", result, GetMacOSStatusCommentString(result)); } exit(result); } return 0; }
另一种方法是将隔离信息从一个文件复制到另一个文件.您可以像这样序列化xattr信息:
xattr -p com.apple.quarantine file > file.xattr
然后,您可以将这些属性应用于其他文件,如下所示:
xattr -w com.apple.quarantine "`cat file.xattr`" file
(这应该可行,但我没有特别检查过它.我使用类似的技术来保存代码签名并重新应用它们.)