Ios 如何以编程方式获取已安装mapbox SDK的当前版本?

Ios 如何以编程方式获取已安装mapbox SDK的当前版本?,ios,mapbox,Ios,Mapbox,我在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[]; 这些似乎是全局导出,我可以使用MapboxVe

我在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

的东西。您可以通过创建一个使用给定标识符初始化的
捆绑包
实例,从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")")
}

今天检查macos SDK包标识符是“com.mapbox.mapbox”