gpt4 book ai didi

ios - 直接从我自己的 iOS 应用程序打开 Microsoft Office 文档进行就地编辑

转载 作者:行者123 更新时间:2023-12-02 19:15:10 24 4
gpt4 key购买 nike

我希望能够就地编辑托管在我自己的服务器上的 Office 文件。我所说的就地是指在 Office 中打开文件,对其进行编辑,然后将更改直接发送回我的应用程序/服务器。

我通过实现 File Provider Extension 部分实现了这一目标在"file"应用程序 (iOS 11+) 中显示我的文件,它会自动启动 Office 应用程序并将更改上传到我的服务器。我还可以从 Office 的“打开”菜单浏览到我的文件并就地进行编辑。

我会直接从我的应用程序触发此流程。有什么想法吗?

我和many已尝试遵循 Microsoft 的 Integrate with Office指南,但它仅适用于 FileShare 或 OneDrive 中托管的文件。我想编辑托管在我自己的服务器中的文件。

最佳答案

我设法让它工作(iOS 11+):

首先,您需要为您的应用程序提供一个可用的文件提供程序扩展。我已经有了。

然后将我的扩展的文件提供程序和文件提供程序项类添加到我的主应用程序。该扩展唯一不起作用的是尝试访问文件提供程序的 documentStorageURL。我通过在自定义类中实现 getter 来修复此问题:

- (NSURL *)documentStorageURL
{
return NSFileProviderManager.defaultManager.documentStorageURL;
}

然后我可以初始化它并从我的主应用程序中使用它:

// I created a singleton for my custom FileProvider class
NSURL* url = [FileProvider.sharedFileProvider URLForItemWithPersistentIdentifier:item.itemIdentifier];

// Calling providePlaceholderAtURL is key
[FileProvider.sharedFileProvider providePlaceholderAtURL:url completionHandler:^(NSError * _Nullable error)
{
if (error)
{
// ...
}

// This will download the requested file from my server
[FileProvider.sharedFileProvider startProvidingItemAtURL:url completionHandler:^(NSError * _Nullable error)
{
[APP_DELEGATE hideHUD];

if (error)
{
// ...
}

// Now I can use the url to start a UIDocumentInteractionController
UIDocumentInteractionController * controller = [UIDocumentInteractionController interactionControllerWithURL:url];
// Call presentOpenInMenuFromRect ...
}];
}];

这使得 Word(以及其他 Office 和应用程序)显示“在 Word 中打开”而不是“复制到 Word”,从而允许直接从我的应用程序进行就地编辑。

使用我的扩展程序的类并调用 providePlaceholderAtURL (这会创建隐藏的 (.myfile.docx.icloud 文件))神奇地使 Word 相信该文件来自"file"应用.

关于ios - 直接从我自己的 iOS 应用程序打开 Microsoft Office 文档进行就地编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52223918/

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