FileExistsAtPath: does not return correct value in iOS 8 SDK

My app worked fine in iOS 7 and now I am facing some new bugs after switching to the iOS 8 SDK.

For example. [NSFileManager defaultManager]

The file existence check ( fileExistsAtPath:

) method no longer works. Here are the details about the current situation in my code:

  • This is a block of code whose state never turns True

    :

    File *tempFile = currentMessage.contains;
    NSString *address = tempFile.thumbAddress;
    
    if ([[NSFileManager defaultManager] fileExistsAtPath:currentMessage.contains.thumbAddress])
    {
        image = [UIImage imageWithContentsOfFile:currentMessage.contains.thumbAddress];
    }
    
          

  • I put a breakpoint in front of the if and traced it to see what it contained:

    Printing description of address:
    /Users/Unkn0wn/Library/Developer/CoreSimulator/Devices/C07E1D76-372E-4C9A-8749-50D369294FBA/data/Containers/Data/Application/1DC7DB3A-B0A2-43AE-9EDA-3E121786D1AA/Documents/FileAt141406917489510096thumbnail.jpg
    
          

  • I checked Finder to see if the file actually exists (the address was copied from the console, so there is no possibility of typos and typos when checking for the existence of a path and file):

enter image description here

But this block is if

not executed because it fileExistsAtPath:

returns NO

.

Am I missing something or is this just a bug in the new SDK? (Because it works fine with SDK 7.1.1)

Any suggestions are greatly appreciated.

thank

+3


source to share


1 answer


If thumbAddress

is a full path (not relative), it may cause errors when updating the application because the application folder changes, for example, your first version of the application might be in this path:

/Users/Unkn0wn/Library/Developer/.../Application/ABCD/

      

When updating the application, the directory will change, for example:

/Users/Unkn0wn/Library/Developer/.../Application/EFGH/

      

So, if you store the full path for your image in the first version of the app, for example:

ABCD/yourImage.jpg

      

And try to restore this image with a newer version of the app, this image will not be found anymore as your image will now be on the path:



EFGH/yourImage.jpg

      

Hope it helps!


EDIT

Perhaps your absolute path is wrong. Try calling it a relative path:

NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
path = [path stringByAppendingString:@"FileAt141406917489510096thumbnail.jpg"];

NSData *imageData = [NSData dataWithContentsOfFile:path]; // Should be != nil

      

+7


source







All Articles