What happens if the file already exists and you try to write it?

Will this correspond or is it impossible to write?

NSData * pdfData = [[NSData alloc] initWithData:[PDFImageConverter convertImageToPDF: [image image]]];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString * filename = sharedManager.localFileName; //file name already exists
    NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:filename];
    [pdfData writeToFile:pdfPath atomically:YES];
    [pdfData release];
+5
source share
3 answers

It will be overwritten if the recording is successful. Please note that if atomic dialing is set to YES, the source file will not be damaged if the recording fails. If atomically set to NO, it will be.

+9
source

If you want to check if a file exists or not, and want to delete it before saving another PDF file, the following is the code

BOOL success = [FileManager fileExistsAtPath:zipPath];
    if(success){
        [FileManager removeItemAtPath:zipPath error:&error];
    }
+2
source

. API- , . ,

[[PHAssetResourceManager defaultManager] writeDataForAssetResource:toFile:options:completionHandler:];

, API API.

0

All Articles