开发者

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:filep开发者_C百科ath ] 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

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

original.png

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

Welcome any comment

Thanks

Marc


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜