如何获得CFBundleShortVersionString为常数
问题描述:
我追加部分恒定的基础URL字符串在我的代码,例如:如何获得CFBundleShortVersionString为常数
#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我想最后的网址是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:@"_"]]