在StackOverflow和其他地方有很多关于如何清除Mac隔离属性的信息。在我的例子中,我想设置它。这是为了测试我的应用程序是否正确地签名,以便用户在下载后会收到“不受信任的开发人员”警告。
我的应用程序特别大(我们从一个大型文件下载站点发布,而不是商店),并且不方便上传和下载来测试这一点。在过去的一周里,我经历了一些代码签名的斗争,所以这个测试对我来说很重要。
一旦文件具有隔离属性,我将了解如何将其更改为具有以下值:
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)但我一开始就不知道该怎么给它财产。
发布于 2014-02-06 01:35:51
这方面的代码并不难,但您需要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(这应该是可行的,但我还没有对它进行特别的隔离试验。)我使用类似的技术保存代码签名并重新应用它们。)
https://stackoverflow.com/questions/21591485
复制相似问题