0

I need to get the already existing pdf files in the device and to upload the selected pdf to the server. I've added one pdf file to iBooks and then tried searching that file in directory using this code:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSFileManager *fileManager = [NSFileManager defaultManager];
//NSError *error = nil;
NSArray *filesAtPath = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil];
NSLog(@"filesAtpath:%@",filesAtPath);
for (NSString *path in filesAtPath)
{
    NSLog(@"add..");
    if ([path rangeOfString:@".pdf"].length > 0)
    {
        //Do whatever you want with the pdf file
        NSLog(@"pdf: %@",path);
    }
}

but the log shows empty array, could you please tell me, is there any other method to get the pdf list in the device and select one to upload in the server.

Neeku
  • 3,646
  • 8
  • 33
  • 43
  • 2
    You cannot access pdf files directly from the other app. As each application has sandbox. So Your PDF will be in iBooks sandbox. According to me there is no direct method to access PDF in device. There are some other ways but that are not like you can view all the PDF in system those totally depend upon user action. – Saurav Nagpal Jun 27 '14 at 11:04
  • is there any other method to add pdf in one app or any file and get those pdf lists to upload to the app? – Amalnath N D Jun 27 '14 at 11:08
  • According to me no we cannot access it directly. One method is there like your app should register as PDF reader and when user click any PDF in device it will display app list and ask user to select app. Then your app can has access to that PDF. And there is one new feature in iOS8 App Extension just go through it and check if it helpful to you or not. – Saurav Nagpal Jun 27 '14 at 11:16
  • @SauravNagpal add as an answer I'll approve as an answer – Amalnath N D Jun 14 '18 at 11:34

1 Answers1

0

No, Apple does not provide access to iBooks library in the same way that it provides some access to the Music library.