我在MapBox.h中找到了这些行:
/// Project version number for Mapbox.
FOUNDATION_EXPORT MGL_EXPORT double MapboxVersionNumber;
/// Project version string for Mapbox.
FOUNDATION_EXPORT MGL_EXPORT const unsigned char MapboxVersionString[];
这些似乎是全球导出,我可以在我的代码中随时随地使用MapboxVersionNumber
和MapboxVersionString
访问它们。但是,它们都是 5 位数字(如果您计算双精度上的.0
,则为 6 位数字(。我一直在寻找更像4.0.1
的东西
您可以通过创建使用给定标识符初始化的Bundle
实例来从 Mapbox Info.plist 文件中提取信息
在 Swift 4.2 中,你可以试试这个:
extension Bundle {
var releaseVersionNumber: String? {
// Actually retrieves the information from the plist.
return infoDictionary?["CFBundleShortVersionString"] as? String
}
var buildVersionNumber: String? {
// Actually retrieves the information from the plist.
return infoDictionary?["CFBundleVersion"] as? String
}
static var mapbox: Bundle {
// Crash can occur if you are not linking Mapbox and "com.mapbox.sdk.ios" does not exist.
return Bundle.init(identifier: "com.mapbox.sdk.ios")!
}
}
然后,您可以在项目中的任何位置使用它:
let mapboxVersion = Bundle.mapbox.releaseVersionNumber
print("Mapbox version: (mapboxVersion)")
注意:如果 Mapbox 以某种方式决定更改其标识符字符串,或者如果您想对另一个框架执行相同的操作,则可以打印所有现有的嵌入框架:
for frameworkBundle in Bundle.allFrameworks {
print("Framework bundle identifier: (frameworkBundle.bundleIdentifier ?? "No identifier")")
}
在调试器中,通过添加新表达式来获取所有框架的列表:
NSBundle.allFrameworks
展开结果。使用右下角的"过滤器",您可以搜索术语"mapbox"。确定框架后,可以通过将其复制到新表达式来引用它及其地址,并查询如下所示的字符串:
[(NSBundle *)0x00000002802f8730 objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
今天检查macos SDK的捆绑标识符是"com.mapbox.Mapbox"。