ios - 如何获取 CFBundleShortVersionString 作为常量

标签 ios objective-c version nsbundle compile-time-constant

我在我的代码中将部分附加到常量基本 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/

相关文章:

tomcat - Websphere Application Server 7 中包含什么版本的 Tomcat

ios - iOS 7 中的长屏幕标题缺少后退按钮标题

ios - CGContext 线宽

ios - 在 UITableView 中默认重新加载后如何记住选择的行并维护它们?

repository - Mercurial-是否可以在同一仓库中 merge 从主干到分支的更改?

Webpack BannerPlugin 创建单独的许可文件

ios - 隐藏导航栏并移动表格 View 部分标题

ios - 导航页面中的相同背景图像

ios - 什么是 Objective-C 中的 SUPER - iOS

objective-c - UITabBarItem 和图标大小