每次開發後會編譯釋出給專案經理測試,然而有時候會忘記該裝置是舊的版本,因為有太多測試機在公司,拿來拿去也編來編去,測完後隔幾天就不小心拿到舊版本的機子,就很有可能測出不期望的bug出來,這實在耗費時間哪~
現在想把編譯日期和時間顯示在App首頁下方,如此就能很清楚知道該版本的新舊。
/** Theme: Display Compile Date and Time IDE: Xcode 7 Language: Objective C Date: 105/07/05 Author: HappyMan Blog: https://cg2010studio.wordpress.com/ */ -(void)displayDevelopmentInfo { #ifdef DEBUG developLabel.textAlignment = NSTextAlignmentCenter; developLabel.numberOfLines = 0; developLabel.backgroundColor = [UIColor clearColor]; NSString *dateTimeString = [NSString stringWithFormat:@"%s %s", __DATE__, __TIME__]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; [formatter setDateFormat:@"MMM dd yyyy HH:mm:ss"]; NSDateFormatter *displayFormatter = [[NSDateFormatter alloc] init]; [displayFormatter setDateFormat:@"yyyy MM/dd HH:mm"]; developLabel.text = [NSString stringWithFormat:@"Happy Develop Build \ncopyright © all rights reserved\n%@", [displayFormatter stringFromDate:[formatter dateFromString:dateTimeString]]]; #endif }
用到__DATE__和__TIME__,說明如下:
- __DATE__:在程式碼中插入當前的編譯日期
- __TIME__:在程式碼中插入當前編譯時間
從此以後,不用擔心測試錯誤的版本:D~
至於編譯時自動判斷Debug或Release可參考:測試Debug與Release模式。
隨意留個言吧:)~