Apple 事件的临时异常在 macOS Sierra 中停止工作
Temporary-Exception for Apple Events stopped working in macOS Sierra
社区,
我需要一些关于 macOS 沙盒应用程序的建议。我已经花了几天时间来解决这个问题,到目前为止还没有结果。我怀疑我的案例在进一步的 macOS 更新中将不再适用。
我的应用程序的功能:
我的应用程序直接通过脚本桥从 Evernote.app 获取 Evernote 笔记列表,然后加密这些笔记,然后将它们上传回来。
问题:
自 Sierra 更新以来,我无法将附件数据写入我的应用程序沙盒文件夹。
我的应用程序的授权文件是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.temporary-exception.apple-events</key>
<string>com.evernote.Evernote</string>
<key>com.apple.security.app-sandbox</key>
<true/>
</dict>
</plist>
我正在使用脚本桥从我的沙盒应用程序中使用 Evernote 应用程序:
EvernoteApplication *evernote = [SBApplication applicationWithBundleIdentifier:@"com.evernote.Evernote"];
然后我在本地笔记本中记下笔记列表:
return [evernote findNotes:[NSString stringWithFormat:@"notebook:\"%@\"",notebookName]];
然后我浏览返回的笔记数组,将每个附件保存到 NSTemporaryDirectory() + 文件名。
[notes enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
EvernoteNote *note = obj;
NSArray *localURLs = [self saveLocalAttachments:note.attachments];
[localURLs enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSURL *localURL = obj;
NSLog(@"URL for resource: %@", [localURL absoluteString]);
}];
}];
保存文件的函数是这样的:
-(NSArray *)saveLocalAttachments:(NSArray *)attachments {
NSLog(@"Started converting resources to files: Total attachments:%lu",[attachments count]);
//
NSMutableArray *resourcesURLs = [[NSMutableArray alloc] initWithCapacity:[attachments count]];
[attachments enumerateObjectsUsingBlock:^(EvernoteAttachment * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
EvernoteAttachment *attach = obj;
//First we write data to local file (inside our sandbox)
NSString *filename = [attach.filename get];
NSURL *localURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:filename]];
NSLog(@"Local URL is:%@",[localURL absoluteString]);
@try {
[attach writeTo:localURL];
} @catch (NSException *exception) {
NSLog(@"Exception writing to local file. Exception: %@",exception);
//[self showAlertWithTitle:@"Writing Data" andMessage:[NSString stringWithFormat:@"Exception in writing temporary data. Exception name: %@, \n description: %@",exception.name, exception.description] andStyle:NSCriticalAlertStyle];
}
//NSLog(@"Attachment saved to: %@",[localURL absoluteString]);
//adding url to the array
@try {
[resourcesURLs addObject:localURL];
}
@catch (NSException *exception) {
NSLog(@"Exception adding URL to array of resourceURLs:%@",exception);
//[self showAlertWithTitle:@"Resource URL" andMessage:exception.description andStyle:NSCriticalAlertStyle];
}
}];
return resourcesURLs;
}
函数 [attach writeTo:(URL)] 在控制台日志中给我一个错误:
SandboxViolation: Evernote(20296) deny file-write-create /private/var/folders/h8/1q71ktcd6fv_rbcd9ygkv6c80000gn/T/com.test.TestEvernoteBridge/example.pdf
Violation: deny file-write-create /private/var/folders/h8/1q71ktcd6fv_rbcd9ygkv6c80000gn/T/com.test.TestEvernoteBridge/example.pdf
Process: Evernote [20296]
我试过的:
- 在 El Capitan 上测试过 - 一切都很好。
- 尝试将权利文件标签从字符串更改为数组,并在其中添加 com.evernote.Evernote 的例外。
- 尝试添加脚本权利 - Evernote sdef 不支持它。
- 从头开始创建新项目以测试任何更新错误 - 都是一样的。
- 删除了沙箱授权 - 问题仍然存在。
- 删除安全异常 - 我没有得到注释列表(这是正确的行为)。
- 尝试通过添加另一个例外来允许写入下载文件夹 - 问题仍然存在。
我不明白为什么它不起作用以及如何获取 Evernote 笔记附件数据。我想这与保护沙盒应用程序 NSTemporaryDirectory 的一些机制有关。我在这里做错了一些事情,我需要一些建议。
这里是测试项目-Test Project
提前致谢。
Apple 对我的错误报告给出了答案——字面意思是:
"Duplicate of 29717097 (Closed)".
我没有看到 29717097 报告(经过更正的 SW 版本),但它仍然无法正常工作。
---更新 08.04.2017 ----
最近的 macOS Sierra 10.12.4 更新解决了这个问题。
社区,
我需要一些关于 macOS 沙盒应用程序的建议。我已经花了几天时间来解决这个问题,到目前为止还没有结果。我怀疑我的案例在进一步的 macOS 更新中将不再适用。
我的应用程序的功能: 我的应用程序直接通过脚本桥从 Evernote.app 获取 Evernote 笔记列表,然后加密这些笔记,然后将它们上传回来。
问题:
自 Sierra 更新以来,我无法将附件数据写入我的应用程序沙盒文件夹。
我的应用程序的授权文件是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.temporary-exception.apple-events</key>
<string>com.evernote.Evernote</string>
<key>com.apple.security.app-sandbox</key>
<true/>
</dict>
</plist>
我正在使用脚本桥从我的沙盒应用程序中使用 Evernote 应用程序:
EvernoteApplication *evernote = [SBApplication applicationWithBundleIdentifier:@"com.evernote.Evernote"];
然后我在本地笔记本中记下笔记列表:
return [evernote findNotes:[NSString stringWithFormat:@"notebook:\"%@\"",notebookName]];
然后我浏览返回的笔记数组,将每个附件保存到 NSTemporaryDirectory() + 文件名。
[notes enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
EvernoteNote *note = obj;
NSArray *localURLs = [self saveLocalAttachments:note.attachments];
[localURLs enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSURL *localURL = obj;
NSLog(@"URL for resource: %@", [localURL absoluteString]);
}];
}];
保存文件的函数是这样的:
-(NSArray *)saveLocalAttachments:(NSArray *)attachments {
NSLog(@"Started converting resources to files: Total attachments:%lu",[attachments count]);
//
NSMutableArray *resourcesURLs = [[NSMutableArray alloc] initWithCapacity:[attachments count]];
[attachments enumerateObjectsUsingBlock:^(EvernoteAttachment * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
EvernoteAttachment *attach = obj;
//First we write data to local file (inside our sandbox)
NSString *filename = [attach.filename get];
NSURL *localURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:filename]];
NSLog(@"Local URL is:%@",[localURL absoluteString]);
@try {
[attach writeTo:localURL];
} @catch (NSException *exception) {
NSLog(@"Exception writing to local file. Exception: %@",exception);
//[self showAlertWithTitle:@"Writing Data" andMessage:[NSString stringWithFormat:@"Exception in writing temporary data. Exception name: %@, \n description: %@",exception.name, exception.description] andStyle:NSCriticalAlertStyle];
}
//NSLog(@"Attachment saved to: %@",[localURL absoluteString]);
//adding url to the array
@try {
[resourcesURLs addObject:localURL];
}
@catch (NSException *exception) {
NSLog(@"Exception adding URL to array of resourceURLs:%@",exception);
//[self showAlertWithTitle:@"Resource URL" andMessage:exception.description andStyle:NSCriticalAlertStyle];
}
}];
return resourcesURLs;
}
函数 [attach writeTo:(URL)] 在控制台日志中给我一个错误:
SandboxViolation: Evernote(20296) deny file-write-create /private/var/folders/h8/1q71ktcd6fv_rbcd9ygkv6c80000gn/T/com.test.TestEvernoteBridge/example.pdf
Violation: deny file-write-create /private/var/folders/h8/1q71ktcd6fv_rbcd9ygkv6c80000gn/T/com.test.TestEvernoteBridge/example.pdf
Process: Evernote [20296]
我试过的: - 在 El Capitan 上测试过 - 一切都很好。 - 尝试将权利文件标签从字符串更改为数组,并在其中添加 com.evernote.Evernote 的例外。 - 尝试添加脚本权利 - Evernote sdef 不支持它。 - 从头开始创建新项目以测试任何更新错误 - 都是一样的。 - 删除了沙箱授权 - 问题仍然存在。 - 删除安全异常 - 我没有得到注释列表(这是正确的行为)。 - 尝试通过添加另一个例外来允许写入下载文件夹 - 问题仍然存在。
我不明白为什么它不起作用以及如何获取 Evernote 笔记附件数据。我想这与保护沙盒应用程序 NSTemporaryDirectory 的一些机制有关。我在这里做错了一些事情,我需要一些建议。
这里是测试项目-Test Project
提前致谢。
Apple 对我的错误报告给出了答案——字面意思是: "Duplicate of 29717097 (Closed)".
我没有看到 29717097 报告(经过更正的 SW 版本),但它仍然无法正常工作。
---更新 08.04.2017 ----
最近的 macOS Sierra 10.12.4 更新解决了这个问题。