gpt4 book ai didi

macos - NSP粘贴板 : Copying promised file data to other sandboxed apps

转载 作者:行者123 更新时间:2023-12-03 17:09:04 27 4
gpt4 key购买 nike

我的沙盒 Mac 应用程序将图像数据作为“public.jpeg”数据以及 kPasteboardTypeFilePromiseContent 放入粘贴板上。

用于 promise 文件的路径位于我的沙盒应用程序的 Container 文件夹中的某个位置。

这对于允许拖动到 Finder 非常有效,但似乎会导致其他沙盒应用程序出现问题,这些应用程序优先考虑 promise 的文件数据而不是图像数据,例如Apple 的 Pages 应用程序。

我找不到在哪里编写 promise 文件的文档,以便其他沙盒应用程序可以访问它。欢迎任何提示。

NSURL *url = [NSURL fileURLWithPath:self.libraryImage.filePath];
if (url)
{
[pasteboardItem setDataProvider:dataProvider
forTypes:@[(NSString *)kPasteboardTypeFilePromiseContent]];
}

更新:

我通过使用此处发布的 NSPasteBoard 扩展得到了一些工作:https://stackoverflow.com/a/18561956/581784

唯一缺少的就是将文件写入用户桌面上放置结束的特定位置。我当前的代码如下所示:

- (void)pasteboard:(nullable NSPasteboard *)pasteboard item:(NSPasteboardItem *)item provideDataForType:(NSString* /* NSPasteboardType */)type
{
if ([type isEqualToString:(NSString *)kPasteboardTypeFileURLPromise])
{
NSURL *pasteURL = [pasteboard pasteLocation];
if (pasteURL) {
NSString *listingImageUUID = [item stringForType:kGSListingImageUUIDPasteboardType];
GSListingImage *listingImage = (GSListingImage*) [[[GSAppDelegate appDelegate] mainDatabaseContext] objectWithUUID:listingImageUUID ofClass:GSListingImage.class];
NSString *imageName = [listingImage.libraryImage.filePath lastPathComponent];
NSURL *destURL = [pasteURL URLByAppendingPathComponent:imageName];

[[listingImage.libraryImage jpegData] writeToURL:destURL
atomically:YES];

[pasteboard setPasteLocation:destURL];
}
}
}

最佳答案

I cannot find documentation where to write the promised file so other sandboxed apps can access it

这不是它的工作原理。放置目标应用程序首先检查拖动类型是否包含 NSFilesPromisePboardType

如果是这样,目标应用程序使用 -[NSDraggingInfo nameOfPromisedFilesDroppedAtDestination:]PasteboardSetPasteLocation() 设置位置。

然后目标应用程序读取kPasteboardTypeFileURLPromise,这会触发 promise 的文件提供程序应用程序将其写入目标应用程序指定的位置。

您需要在 - (void)pasteboard:(nullable NSPasteboard *)pasteboard item:(NSPasteboardItem *)item ProvideDataForType:(NSPasteboardType)type; 中执行此操作。

关于macos - NSP粘贴板 : Copying promised file data to other sandboxed apps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54038316/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com