Add git transfer SHA to iOS app

I want to show the current git SHA when my project was built in my application. What is a good way to do this in an iOS project with minimal effort?

+8
git ios objective-c iphone xcode
source share
2 answers

You can do this in diagrams. Open your schema (change), expand the assembly in your schema, click "Preliminary Actions", click the "+" button, select "Create Launch" Script Action and write some Script that gets SHA and changes some header file where you can put SHA (the easiest way is #define GIT_SHA @"..." ) and use GIT_SHA in your application in the place where you can display it.

+6
source share

Version 2.17. Create a85b242.

If you want to add nice version control as shown above, follow these steps:

  • Open Build Phases in Xcode
  • Click Add Build Phase
  • Click Add Run Script Build Phase . You can find it in the top menu Editor . Drag the script -line to the position after Target Dependencies .
  • Install Shell on /bin/sh
  • Install the script below in the Script field. Remember to change the Sources to your path to the file where GitVersion.h should be. For example:

     version=$(git rev-parse --verify HEAD | cut -c 1-7) curdate=$(date +"%d.%m.%y") filesource="//\n// GitVersion.h\n//\n// Created by sig on $curdate.\n//\n\n#ifndef GitVersion_h\n#define GitVersion_h\n\n#define GIT_SHA_VERSION @\"$version\"\n\n#endif" cd ${SOURCE_ROOT}/${PROJECT_NAME} echo -e "$filesource" > Sources/GitVersion.h touch Sources/GitVersion.h 
  • Import the GitVersion.h file into your Xcode project

  • Insert these lines:

     NSDictionary *info = [[NSBundle mainBundle] infoDictionary]; NSString *version = [info objectForKey:@"CFBundleShortVersionString"]; NSString *app_version = [NSString stringWithFormat:@"Version %@. Build %@.", version, GIT_SHA_VERSION]; NSLog(@"app_version : %@", app_version); 

A fully documented answer with images and described benefits can be found here .

+16
source share

All Articles