在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)
但是我不知道如何首先赋予它财产。
用于此的代码并不难,但是您需要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
(这应该起作用,但是我没有特别进行隔离测试。我使用类似的技术来保存代码签名并重新应用它们。)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句