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

标签 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[];

那些似乎是全局导出,我可以在代码中的任何地方使用 MapboxVersionNumberMapboxVersionString 访问它们。但是,它们都是 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/

相关文章:

ios - 在 iOS 中使用 Cordova 打开本地 pdf

javascript - 如何将事件附加到 TileMill 中创建的 Natural Earth map 数据?

JavaScript - 如何为红线绘制黑色轮廓(或描边) - leaflet mapbox

mapbox - 将本地osrm服务器添加到mapbox gl方向

javascript - Mapbox/Leaflet .bottom 控件在 map 上方呈现并且看不见

ios - 章节标题困惑

ios - zbar SDK 不适用于 armv7s(iPad 4 iOS 7)

ios - 从 Xcode 项目构建两个输出

ios - 图片查看动画

javascript - Mapbox 在点击事件上更改缩放