简体   繁体   English

“ [[[NSBundle mainBundle] objectForInfoDictionaryKey:]”有时返回nil

[英]“[[NSBundle mainBundle] objectForInfoDictionaryKey:]” sometimes returns nil

I'm trying to retrieve some URLs from the infoDictionary . 我正在尝试从infoDictionary检索一些URLs 9 times out of 10, the URLs are returned correctly. 十分之9的URLs正确返回。 However, very occasionally, the URLs will return nil. 但是, URLs偶尔会返回nil。 Any idea what might be causing this behavior? 任何想法可能导致此行为?

[NSBundle mainBundle] and [[NSBundle mainBundle] infoDictionary] are both not nil when this strange behavior occurs. 当发生这种奇怪的行为时, [NSBundle mainBundle][[NSBundle mainBundle] infoDictionary]都不为零。 Only the URLs return nil. 只有URLs返回零。

In iOS it is not possible to write to the app bundle so trying to do so will fail. 在iOS中,无法写入应用捆绑包,因此尝试这样做将失败。 Typically data is written to and read from a file in the app's document directory which can be obtained as follows: 通常,将数据写入和读取应用程序文档目录中的文件,该文件可以按以下方式获取:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths firstObject];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:myFileName];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM