Showing App's Build Date

后端 未结 6 896
情书的邮戳
情书的邮戳 2021-02-04 05:23

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 doe

6条回答
  •  故里飘歌
    2021-02-04 05:48

    If you redefine __DATE__ and __TIME__ it will make the time update every time you build your app. you won´t need to clean or archive to update the time, just need run the project.

      #define DATE [NSString stringWithUTF8String:__DATE__]
      #define TIME [NSString stringWithUTF8String:__TIME__]
    
    
    - (NSString *)getBuildDate {
        NSString *buildDate;
    
        // Get build date and time, format to 'yyMMddHHmm'
        NSString *dateStr = [NSString stringWithFormat:@"%@ %@", DATE , TIME ];
    
        // Convert to date
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:@"LLL d yyyy HH:mm:ss"];
        NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
        [dateFormat setLocale:usLocale];
        NSDate *date = [dateFormat dateFromString:dateStr];
    
        // Set output format and convert to string
        [dateFormat setDateFormat:@"dd/MM/yyyy-HH:mm"];
        buildDate = [dateFormat stringFromDate:date];
    
        return buildDate;
    }
    

提交回复
热议问题