Search code examples
phpiosobjective-cxcodensdocument

Select File Name created with Date and Time for later use?


 NSString *dateString= [self currentDateandTime];

//create file path and file name

  NSString *docDirectory =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *pdfPath = [docDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"602_TW0023.%@_pdf.pdf",dateString]];
NSLog(@"Path: %@", pdfPath);

i converted an image to pdf and saved it with current date and time. How can i use this file to upload to ftp or php.

NSString* theFileName = [pdfPath lastPathComponent];

how to call above string into other method.can we set tag or what? i'm new to programming. point me right direction.

i tried a lot.

NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filepath =[NSString stringWithFormat: @"%@/%@",applicationDocumentsDir, @"%@"];

NSData *uploadData = [NSData dataWithContentsOfFile: filepath];

Solution

  • in your class.h:

     @property(strong,nonatomic)NSString *filepath;
    

    when you create the file path add:

    self.filepath=pdfPath;
    

    Then, when creating the data to upload use:

    NSData *uploadData =[NSData dataWithContentsOfFile:self.filepath];
    

    this will make sure you have the same file path when saving and reading the pdf