skiptools / skip-foundation

Foundation module for Skip apps.
https://skip.tools
GNU Lesser General Public License v3.0
8 stars 8 forks source link

infoDictionary API Not Available #12

Closed larson-carter closed 2 days ago

larson-carter commented 4 months ago
This API is not yet available in Skip. 
Consider placing it within a #if !SKIP block. 
You can file an issue against the owning library at https://github.com/skiptools, 
or see the library README for information on adding support

The infoDictionary deriving from the Main Bundle package in Swift's Foundational Package is not available in Skip Yet.

Code example:

        guard let currentAppVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String else {
            return false
        }
marcprux commented 4 months ago

We do not support bundle info dictionaries, as the Info.plist file won't be installed with your Android app.

So to get the current version number for the app on Android, you can do something like this:

let appVersion: String? = {
    #if !SKIP
    return Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
    #else
    let context = ProcessInfo.processInfo.androidContext
    let packageManager = context.getPackageManager()
    let packageInfo = packageManager.getPackageInfo(context.getPackageName(), android.content.pm.PackageManager.GET_META_DATA)
    let versionName = packageInfo.versionName
    let versionCode = packageInfo.versionCode
    return versionName
    #endif
}()
marcprux commented 2 days ago

I've implemented a synthesized Bundle.main.infoDictionary with commonly-used keys like CFBundleShortVersionString and CFBundleIdentifier in https://github.com/skiptools/skip-foundation/pull/27. You can get it by updating to skip-foundation 1.1.8.