我在 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")")
}
关于ios - 如何以编程方式获取已安装的 mapbox SDK 的当前版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50883096/