我在我的代码中将部分附加到常量基本 URL 字符串:
#define BASE_URL @"https://example.com/developer/"
#define PHP_SCRIPT BASE_URL @"index.php"
使得生成的 PHP_SCRIPT 引用 https://example.com/developer/index.php
我正在寻找一种方法将我的应用程序的 CFBundleShortVersionString
插入到此串联中。 例如,如果 CFBundleShortVersionString 是 1.12,我希望最终 URL 是 https://example.com/developer/1_12/
我知道 CFBundleShortVersionString
可以被访问
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
和
(__bridge NSString *)(CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey))
但我需要帮助才能将它连接成常量字符串。
最佳答案
应该这样做。
#define BASE_URL @"https://example.com/developer/"
#define PHP_SCRIPT [NSString stringWithFormat:@"%@%@/", BASE_URL, [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] stringByReplacingOccurrencesOfString:@"." withString:@"_"]]
关于ios - 如何获取 CFBundleShortVersionString 作为常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25527217/