I've declared a custom export UTI type in a simple Document Based iOS app. I'm now trying to provide the capability to import files of the same type from Mail to the app.
When long-pressing the document icon in the message, I'm given the option to "copy to MyApp" which then calls the method in 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;
}
However the document is presented, but not imported (the revealedDocumentURL
is the same as inputURL
, and the delegate method importDocumentAtURL
is not called). Maybe I shouldn't be using the revealDocumentAtURL method? I cannot use the importDocumentAtURL: nextToDocumentAtURL: mode: completionHandler:
method since I can't specify a document for the nextToDocumentAtURL
parameter. Is there a way to import a document to a specific directory? Maybe I'm missing something quite obvious? Also, here's my info.plist file in case it proves helpful.
<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>
It appears that this was an issue in iOS 11.2. Upgrading iOS to 11.3 and Xcode to 9.3 fixed the problems.