我已经在一个简单的基于文档的 iOS 应用程序中声明了一个自定义导出 UTI 类型。我现在正在尝试提供将相同类型的文件从 Mail 导入应用程序的功能。
当长按消息中的文档图标时,我可以选择“复制到 MyApp”,然后调用 AppDelegate.m 中的方法:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)inputURL options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
DocumentBrowserViewController *documentBrowserViewController = (DocumentBrowserViewController *)self.window.rootViewController;
[documentBrowserViewController revealDocumentAtURL:inputURL importIfNeeded:YES completion:^(NSURL * _Nullable revealedDocumentURL, NSError * _Nullable error) {
if (error) {
NSLog(@"Failed to reveal the document at URL %@ with error: '%@'", inputURL, error);
return;
}
NSLog(@"Imported document to %@",[revealedDocumentURL absoluteString]);
[documentBrowserViewController presentDocumentAtURL:revealedDocumentURL];
}];
return YES;
}
然而,文档被呈现,但没有被导入(revealedDocumentURL
与 相同,并且不调用inputURL
委托方法)。importDocumentAtURL
也许我不应该使用revealDocumentAtURL 方法?我无法使用该importDocumentAtURL: nextToDocumentAtURL: mode: completionHandler:
方法,因为我无法为nextToDocumentAtURL
参数指定文档。有没有办法将文档导入特定目录?也许我错过了一些非常明显的东西?另外,这是我的 info.plist 文件,以防它被证明有帮助。
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>MyApp File</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.myCompany.MyApp</string>
</array>
<key>LSSupportsOpeningDocumentsInPlace</key>
<false/>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<false/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportsDocumentBrowser</key>
<true/>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UITypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>myext</string>
</array>
</dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
<string>public.content</string>
</array>
<key>UTTypeDescription</key>
<string>MyApp File</string>
<key>UTTypeIdentifier</key>
<string>com.myCompany.MyApp</string>
</dict>
</array>
</dict>
</plist>