0

I am picking documents from iCloud and google drive etc and using this method - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url

I am getting the url file:///private/var/mobile/Containers/Data/Application/34C6FC23-C8BF-407E-AD67-77758BD606E9/tmp/com.company.theApp-Inbox/chart%20(1).pdf

but when I am doing this [[NSFileManager defaultManager]copyItemAtURL:url toURL:docUrl error:&error];

I am getting this error Error Domain=NSCocoaErrorDomain Code=262 "The file couldn’t be opened because the specified URL type isn’t supported." UserInfo={NSURL=/var/mobile/Containers/Data/Application/34C6FC23-C8BF-407E-AD67-77758BD606E9/Documents/documents/12345678901-1470638583.pdf}

and this is my docUrl = /var/mobile/Containers/Data/Application/34C6FC23-C8BF-407E-AD67-77758BD606E9/Documents/documents/12345678901-1470638583.pdf

S.J
  • 3,063
  • 3
  • 33
  • 66

3 Answers3

2

Try initialising your docUrl with:

NSURL *docUrl = [[NSURL alloc] initFileURLWithPath:@"/var/mobile/Containers/Data/Application/34C6FC23-C8BF-407E-AD67-77758BD606E9/Documents/documents/12345678901-1470638583.pdf"];

I'm guessing that copyItemAtURL:toURL:error: doesn't recognise your URL as a file URL.

Roy
  • 43,878
  • 2
  • 26
  • 26
  • This is what I am doing NSURL *docUrl = [NSURL URLWithString:[documentFolderDataPath stringByAppendingPathComponent:fn]]; – S.J Aug 08 '16 at 07:48
  • And if you change that to: `NSURL *docUrl = [NSURL fileURLWithPath:[documentFolderDataPath stringByAppendingPathComponent:fn]];`? – Roy Aug 08 '16 at 07:54
0

In swift world:

URL(fileURLWithPath: "/var/mobile/Containers/Data/Application/34C6FC23-C8BF-407E-AD67-77758BD606E9/Documents/documents/12345678901-1470638583.pdf")
Edmund Lee
  • 2,514
  • 20
  • 29
-3

Please try initialising your docUrl with:

NSURL *docUrl = [[NSURL alloc] initFileURLWithPath:@"file:///var/mobile/Containers/Data/Application/34C6FC23-C8BF-407E-AD67-77758BD606E9/Documents/documents/12345678901-1470638583.pdf"]

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416