monsabre
monsabre

Reputation: 2099

dataWithContentsOfFile:filepath of NSData sometimes works, sometimes has no function

I used the codes below to load image file in app bundle. The codes work! imageData does NOT return 0x0

NSMutableString *sss;
sss=[[NSMutableString  alloc] initWithString: [[NSBundle mainBundle] resourcePath]];
[sss appendString:@"/"] ;
[sss appendString:@"thumbnail.png"];
NSData *imageData = [NSData dataWithContentsOfFile:sss];

but the codes below in which almost everything is same have no function, imageData always DOES return 0x0, it looks like [NSData dataWithContentsOfFile:filepath ] does not work for large size image file

NSMutableString *sss;
sss=[[NSMutableString  alloc] initWithString: [[NSBundle mainBundle] resourcePath]];
[sss appendString:@"/"] ;
[sss appendString:@"original.png"];
NSData *imageData = [NSData dataWithContentsOfFile:sss];

Both of thumbnail.png and original.png are in the same directory of main bundle.

thumbnail.png

thumbnail.png

original.png

original.png

Welcome any comment

Thanks

Marc

Upvotes: 0

Views: 5133

Answers (3)

Ken Pespisa
Ken Pespisa

Reputation: 22264

It won't have anything to do with the size of the file. Check and see if you've spelled the file name correctly in your code. The file names are case-sensitive, so if the file is named original.PNG, then you'll need to make sure it is written that way in code as well.

Make sure that the original.png file has been added to your project, and if so, try removing it from your project and re-adding it. When you drag the file into your project, make sure the option "copy files..." is checked.

Upvotes: 3

Erik S
Erik S

Reputation: 1929

I also think that the file has not been added to resources. Check the 'Resources' folder in your xcode project, and if it isnt there, put it in there. Either by dragging it in there, or by rightclicking -> new file.

Upvotes: 1

Mujah Maskey
Mujah Maskey

Reputation: 8804

check out if it really contains on resource . check that file is in: Targets/ProductName/Copy Bundle Resources

Upvotes: 1

Related Questions