Show application version on launch screen using Swift

Scenario

I want to show the version of my iOS 9 application made using Swift.

What I've done

I know how to get version ( let version: String = NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"] as! String)

I also have a custom label on my home screen.

My problem

Now my problem is that it is not allowed to use the native UIViewController for the splash / launch screen.

Many applications display their version directly on this screen. That is why I think there must be a way to do this.

+4
source share
4 answers

UIViewController LaunchScreen, UILabel LaunchScreen xib/Storyboard .

- . - Apple, , , :

error: Illegal Configuration: Launch screens may not set custom classnames

.. , LaunchScreen UIViewConttoller , , .

+4

script . , .

ViewController LaunchScreen.storyboard . "APP_VERSION" " " → "" → "".

script, "+" , "New Run script Phase" , " Bundle".

script :/bin/sh XCode 9 (Swift 4):

#   ON/OFF Script Toggle (script ON with #, script OFF without #)
exit 0

#   Increment build number
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"

#   Output version & build numbers into a label on LaunchScreen.storyboard
versionNumber=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")
sed -i bak -e "/userLabel=\"APP_VERSION\"/s/text=\"[^\"]*\"/text=\"Version: $versionNumber Build: $buildNumber\"/" $PROJECT_DIR/>>>CHANGE ME<<</Base.lproj/LaunchScreen.storyboard

' → > CHANGE ME < < < .

, / script. , - .

+17

You can try to do this with LaunchScreen.storyboard. Try adding a new one LaunchScreento your project using New File -> User Interface -> Launch ScreenIt automatically creates a type storyboard LaunchScreen. Then you can change the startup screen to project settings -> Generalin this section:

enter image description here

And work with this storyboardwith your custom class

0
source

Updated @Repose script

#   ON/OFF Script Toggle (script ON with #, script OFF without #)
#exit 0

#   Increment Build Number Bool (Increment ON with true, increment OFF with false)
shouldIncrement=true

#   App vesion / Build version constants
versionNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE")
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")

#   Increment build number
if [ "$shouldIncrement" = true ]; then
    buildNumber=$(($buildNumber + 1))
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
fi

#   Output version & build numbers into a label on LaunchScreen.storyboard
sed -i bak -e "/userLabel=\"APP_VERSION\"/s/text=\"[^\"]*\"/text=\"Version: $versionNumber Build: $buildNumber\"/" "$PROJECT_DIR/$PROJECT_NAME/Base.lproj/LaunchScreen.storyboard"
0
source

Source: https://habr.com/ru/post/1614852/


All Articles