简体   繁体   中英

How to determine the IOS version from within an Flex mobile app (AIR)

I want to determine whether my Flex mobile app is running on a IOS device with IOS 7.

I need to find out because I want to lower the actionbar of the application if it is run on IOS 7 to provide room for the indicators (battery, wifi, etc.).

According to documentation the Flex Capabilities class does not provide me with an IOS version number.

The only option I can think of is to build a Native extension and query the version using IOS functions. But I do not really look forward to building that extension. Even less so because apparently you need a Mac with XCode to build the IOS part, and I don't own a Mac. A VM with OSX installed could be my last resort.

Maybe you know another option?

Flex 4.12 actually introduced a way to fix this through CSS (4.12 introduced OS and OS version checks as well, which is awesome):

@media (application-dpi: 160) AND (os-platform:"IOS") AND (min-os-version: 7)
{
    Application {
         osStatusBarHeight: 20;
    }
}

But to answer your question, this function does the job:

public static function get iOSVersion():uint {
    var iosVersion:String = Capabilities.os.match( /([0-9]\.?){2,3}/ )[0];
    return Number( iosVersion.substr( 0, iosVersion.indexOf( "." ) ) );
}

I pulled that from my personal AS3 utility library. For sure, this will not work to get the Android version number and I am unsure if it will work for Mac or Windows. It will return the major version number only (minor versions are generally irrelevant). If you want to change that, just return iosVersion in the function instead of the second line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM