首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"[[NSBundle mainBundle] objectForInfoDictionaryKey:]“有时返回空

"[[NSBundle mainBundle] objectForInfoDictionaryKey:]“有时返回空
EN

Stack Overflow用户
提问于 2014-05-12 11:08:52
回答 1查看 1.1K关注 0票数 2

我正试着从infoDictionary中检索一些URLs。10次中有9次正确返回URLs。但是,在极少数情况下,URLs会返回nil。你知道是什么导致了这种行为吗?

当这种奇怪的行为发生时,[NSBundle mainBundle][[NSBundle mainBundle] infoDictionary]都不是空的。只有URLs返回nil。

EN

回答 1

Stack Overflow用户

发布于 2014-05-12 20:40:20

在iOS中,不可能写入应用程序包,因此尝试这样做将失败。通常情况下,数据是从应用程序的文档目录中的文件中写入和读取的,可以按如下方式获取:

代码语言:javascript
复制
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths firstObject];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:myFileName];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23600466

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档