Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing App's Build Date

I am able to display the build date for my app in the simulator, but whenever I archive the app, and upload it to TestFlight, and then install it on a device, the build date doesn't show.

Here is what I'm doing to display the build date.

First, I added CFBuildDate as a string to myproject-info.plist

Next, I added the following script to Edit Scheme -> Build -> Pre-Actions -> Run Script Action :

infoplist="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
builddate=`date`
if [[ -n "$builddate" ]]; then
/usr/libexec/PlistBuddy -c "Add :CFBuildDate $builddate" ${infoplist}
/usr/libexec/PlistBuddy -c "Set :CFBuildDate $builddate" ${infoplist}
fi

Finally, used the following code to get the build date from the plist file :

NSString *build_date = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBuildDate"];

This displays the build date in simulator (though occasionally it doesn't), but when deploying the app through TestFlight, the build date never displays. Any ideas ?

Thanks in advance.

like image 368
Myxtic Avatar asked Aug 02 '12 14:08

Myxtic


2 Answers

You might consider using the built-in __DATE__ and __TIME__ macros which will return a string representation of the date and time the app was built. Perhaps they will be of more help to you:

NSString *dateStr = [NSString stringWithUTF8String:__DATE__];
NSString *timeStr = [NSString stringWithUTF8String:__TIME__];
like image 177
Jeremy Avatar answered Oct 05 '22 22:10

Jeremy


To get build date with format 'yyMMddHHmm' you could try this:

+ (NSString *)GetBuildDate {
    NSString *buildDate;

    // Get build date and time, format to 'yyMMddHHmm'
    NSString *dateStr = [NSString stringWithFormat:@"%@ %@", [NSString stringWithUTF8String:__DATE__], [NSString stringWithUTF8String:__TIME__]];

    // Convert to date
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"LLL d yyyy HH:mm:ss"];
    NSDate *date = [dateFormat dateFromString:dateStr];

    // Set output format and convert to string
    [dateFormat setDateFormat:@"yyMMddHHmm"];
    buildDate = [dateFormat stringFromDate:date];

    [dateFormat release];

    return buildDate;
}
like image 23
Dirk Schmidt Avatar answered Oct 05 '22 22:10

Dirk Schmidt