@@ -304,7 +304,7 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl
304304 return [self application: application openURL: url options: options];
305305}
306306
307- - (BOOL )importFileToDocuments : (NSURL *)url {
307+ - (BOOL )importFileToDocuments : (NSURL *)url copy : ( BOOL ) copy {
308308 if (url.fileURL ) {
309309 // opening file
310310 NSFileManager *fileManager = [NSFileManager defaultManager ];
@@ -322,7 +322,11 @@ - (BOOL)importFileToDocuments:(NSURL *)url {
322322 destinationPath = [self .documentsPath stringByAppendingPathComponent: newFileName];
323323 tries++;
324324 }
325- [fileManager moveItemAtPath: url.path toPath: destinationPath error: &error];
325+ if (copy) {
326+ [fileManager copyItemAtPath: url.path toPath: destinationPath error: &error];
327+ } else {
328+ [fileManager moveItemAtPath: url.path toPath: destinationPath error: &error];
329+ }
326330 if (error) {
327331 [self showAlertWithTitle: fileName message: error.localizedFailureReason];
328332 } else {
@@ -337,16 +341,22 @@ - (BOOL)importFileToDocuments:(NSURL *)url {
337341- (BOOL )application : (UIApplication *)app openURL : (NSURL *)url options : (NSDictionary <UIApplicationOpenURLOptionsKey,id> *)options {
338342 if (url.fileURL ) {
339343 // opening file
340- if ([url.path.stringByStandardizingPath hasPrefix: self .documentsPath]) {
344+ NSString *inboxPath = [self .documentsPath stringByAppendingPathComponent: @" Inbox" ];
345+ if ([url.path.stringByStandardizingPath hasPrefix: inboxPath]) {
346+ // pre-iOS 11 import through inbox
347+ [url startAccessingSecurityScopedResource ];
348+ [self importFileToDocuments: url copy: NO ];
349+ [url stopAccessingSecurityScopedResource ];
350+ } else if ([url.path.stringByStandardizingPath hasPrefix: self .documentsPath]) {
341351 // already in documents - mount
342352 [sharedEmulator insertDisk: url.path];
343353 } else if ([options[UIApplicationOpenURLOptionsOpenInPlaceKey] boolValue ]) {
344354 // not in documents - copy
345355 [url startAccessingSecurityScopedResource ];
346- [self importFileToDocuments: url];
356+ [self importFileToDocuments: url copy: YES ];
347357 [url stopAccessingSecurityScopedResource ];
348358 } else {
349- return [self importFileToDocuments: url];
359+ return [self importFileToDocuments: url copy: NO ];
350360 }
351361 }
352362 return YES ;
0 commit comments