Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
refactor: Update how version numbers are used
Browse files Browse the repository at this point in the history
"Build Version" aka "Bundle Version" or "Current Project Version" is intended to be an internal version.
"Short Version" aka "Marketing Version" is intended to be what is typically displayed to and understood by users.

We were using "Build Version" as the user-understood version, and "Short Version" as just the Major.Minor part of the "Build Version".  This change replaces our use of "Build Version" with "Short Version" in most places, and adds a new "Display Version" that is a concatenation of "Build Version" and "Short Version" for use when displaying the version to users in the app in Login, What's New, and Account screens, as well as for User Agent strings.

IMPORTANT: This change is intended to happen alongside updated usage of "Version" and "Build" strings in the edX target settings.  That is, moving forward, the "Version" string - as the "Short Version" - should be the version that we intend users to see in the App Store, and general understand to be the app version.  The "Build" string should be used to identify exactly which commit/build the app is.
  • Loading branch information
colinbrash committed Sep 10, 2021
1 parent f5174f9 commit 29a9817
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Source/AccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AccountViewController: UIViewController, UITableViewDelegate, UITableViewD
tableView.register(AccountViewCell.self, forCellReuseIdentifier: AccountViewCell.identifier)
let textStyle = OEXMutableTextStyle(weight: .normal, size: .base, color : OEXStyles.shared().neutralBlack())
textStyle.alignment = NSTextAlignment.center
versionLabel.attributedText = textStyle.attributedString(withText: Strings.versionDisplay(number: Bundle.main.oex_buildVersionString(), environment: ""))
versionLabel.attributedText = textStyle.attributedString(withText: Strings.versionDisplay(number: Bundle.main.oex_displayVersionString(), environment: ""))
versionLabel.accessibilityIdentifier = "AccountViewController:version-label"
tableView.accessibilityIdentifier = "AccountViewController:table-view"
addConstraints()
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Code/NSBundle+OEXConveniences.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ NS_ASSUME_NONNULL_BEGIN

/// The user facing version, like 2.1.2
- (NSString*)oex_shortVersionString;
/// The user facing version, like 2.1.23
/// The build number, like 6512
- (NSString*)oex_buildVersionString;
/// The user facing version string, like 2.1.2 (6512)
- (NSString*)oex_displayVersionString;
/// The user facing app name, like edX
- (NSString*)oex_appName;

Expand Down
4 changes: 4 additions & 0 deletions Source/Core/Code/NSBundle+OEXConveniences.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ - (NSString*)oex_buildVersionString {
return [[NSBundle mainBundle] objectForInfoDictionaryKey: (__bridge NSString*)kCFBundleVersionKey];
}

- (NSString*)oex_displayVersionString {
return [NSString stringWithFormat:@"%@ (%@)", [self oex_shortVersionString], [self oex_buildVersionString]];
}

- (NSLocale*)oex_displayLocale {
NSString* localization = [NSBundle mainBundle].preferredLocalizations.firstObject;
NSLocale* locale = [[NSLocale alloc] initWithLocaleIdentifier:localization];
Expand Down
2 changes: 1 addition & 1 deletion Source/OEXAnalytics+AppReview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private let rateTheAppDisplayName = "AppReviews: Rate The App"
extension OEXAnalytics {

private func additionalParams(selectedRating: Int? = nil) -> [String: String] {
var params = [key_app_version : Bundle.main.oex_buildVersionString()]
var params = [key_app_version : Bundle.main.oex_shortVersionString()]
if let rating = selectedRating{
params[key_rating] = String(rating)
}
Expand Down
4 changes: 2 additions & 2 deletions Source/OEXAnalytics+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ extension OEXAnalytics {
event.displayName = AnalyticsDisplayName.CourseSearch.rawValue
event.category = AnalyticsCategory.Discovery.rawValue
event.label = query
trackEvent(event, forComponent: nil, withInfo: ["action": action, "app_version": Bundle.main.oex_buildVersionString()])
trackEvent(event, forComponent: nil, withInfo: ["action": action, "app_version": Bundle.main.oex_shortVersionString()])
}

func trackChromecastConnected() {
Expand Down Expand Up @@ -448,7 +448,7 @@ extension OEXAnalytics {
event.category = OEXAnalyticsCategoryUserEngagement
event.label = AnalyticsCategory.Discovery.rawValue

trackEvent(event, forComponent: nil, withInfo: ["action":"landing_screen","app_version": Bundle.main.oex_buildVersionString()])
trackEvent(event, forComponent: nil, withInfo: ["action":"landing_screen","app_version": Bundle.main.oex_shortVersionString()])
}

func trackResumeCourseTapped(courseID: String, blockID: String) {
Expand Down
2 changes: 1 addition & 1 deletion Source/OEXInterface+AppReview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension OEXInterface {

/// Save the app version when app review is done
func saveAppVersionWhenLastRated(version: String? = nil) {
UserDefaults.standard.set(version ?? Bundle.main.oex_buildVersionString(), forKey: OEXSavedAppVersionWhenLastRated)
UserDefaults.standard.set(version ?? Bundle.main.oex_shortVersionString(), forKey: OEXSavedAppVersionWhenLastRated)
UserDefaults.standard.synchronize()
}

Expand Down
2 changes: 1 addition & 1 deletion Source/OEXInterface+WhatsNew.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private let WhatsNewShownFor = "whats_new_show_for"
extension OEXInterface {
// save current version of app on whatsNew appearance
func saveAppVersionOnWhatsNewAppear() {
UserDefaults.standard.set(Bundle.main.oex_buildVersionString(), forKey: WhatsNewShownFor)
UserDefaults.standard.set(Bundle.main.oex_shortVersionString(), forKey: WhatsNewShownFor)
UserDefaults.standard.synchronize()
}

Expand Down
2 changes: 1 addition & 1 deletion Source/OEXInterface.m
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ - (UserCourseEnrollment*)enrollmentForCourseWithID:(NSString*)courseID {
#pragma mark - App Version

- (void) saveAppVersion {
[[NSUserDefaults standardUserDefaults] setObject:[NSBundle mainBundle].oex_buildVersionString forKey:OEXSavedAppVersionKey];
[[NSUserDefaults standardUserDefaults] setObject:[NSBundle mainBundle].oex_shortVersionString forKey:OEXSavedAppVersionKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}

Expand Down
2 changes: 1 addition & 1 deletion Source/OEXLoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ - (void)viewDidLoad {

NSString* environmentName = self.environment.config.environmentName;
if(environmentName.length > 0) {
NSString* appVersion = [NSBundle mainBundle].oex_buildVersionString;
NSString* appVersion = [NSBundle mainBundle].oex_displayVersionString;
self.versionLabel.text = [Strings versionDisplayWithNumber:appVersion environment:environmentName];
}
else {
Expand Down
2 changes: 1 addition & 1 deletion Source/RatingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RatingViewController: UIViewController, RatingContainerDelegate {
guard let _ = environment.config.appReviewURI, environment.interface?.reachable ?? false && environment.config.isAppReviewsEnabled else { return false }

if let appRating = environment.interface?.getSavedAppRating(), let lastVersionForAppReview = environment.interface?.getSavedAppVersionWhenLastRated(){
let version = Version(version: (Bundle.main.oex_buildVersionString()))
let version = Version(version: (Bundle.main.oex_shortVersionString()))
let savedVersion = Version(version: lastVersionForAppReview)
let validVersionDiff = version.isNMinorVersionsDiff(otherVersion: savedVersion, minorVersionDiff: minimumVersionDifferenceForNegativeRating)

Expand Down
2 changes: 1 addition & 1 deletion Source/UserAgentGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UserAgentGenerator: NSObject {

static var appVersionDescriptor : String {
let bundle = Bundle.main
let components = [bundle.oex_appName(), bundle.bundleIdentifier, bundle.oex_buildVersionString()].compactMap{ return $0 }
let components = [bundle.oex_appName(), bundle.bundleIdentifier, bundle.oex_shortVersionString()].compactMap{ return $0 }
return components.joined(separator: "/")
}

Expand Down
10 changes: 5 additions & 5 deletions Source/WhatsNewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class WhatsNewViewController: UIViewController, UIPageViewControllerDelegate, UI
self.dataModel = dataModel
}
else {
self.dataModel = WhatsNewDataModel(environment: environment as? RouterEnvironment, version: Bundle.main.oex_buildVersionString())
self.dataModel = WhatsNewDataModel(environment: environment as? RouterEnvironment, version: Bundle.main.oex_shortVersionString())
}
titleString = title ?? Strings.WhatsNew.headerText
pageController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
Expand All @@ -52,7 +52,7 @@ class WhatsNewViewController: UIViewController, UIPageViewControllerDelegate, UI
}

static func canShowWhatsNew(environment: RouterEnvironment?) -> Bool {
let appVersion = Version(version: Bundle.main.oex_buildVersionString())
let appVersion = Version(version: Bundle.main.oex_shortVersionString())
let savedAppVersion = Version(version: environment?.interface?.getSavedAppVersionForWhatsNew() ?? "")
let validDiff = appVersion.isNMinorVersionsDiff(otherVersion: savedAppVersion, minorVersionDiff: 1)
return (validDiff && environment?.config.isWhatsNewEnabled ?? false)
Expand Down Expand Up @@ -185,18 +185,18 @@ class WhatsNewViewController: UIViewController, UIPageViewControllerDelegate, UI
//MARK:- Analytics

private func logScreenEvent() {
let params = [key_app_version : Bundle.main.oex_buildVersionString()]
let params = [key_app_version : Bundle.main.oex_shortVersionString()]
environment.analytics.trackScreen(withName: AnalyticsScreenName.WhatsNew.rawValue, courseID: nil, value: nil, additionalInfo: params)
}

private func logCloseEvent() {
(pagesViewed == 1) ? (pagesViewed = pagesViewed) : (pagesViewed -= 1)
let params = [key_app_version : Bundle.main.oex_buildVersionString(), "total_viewed": pagesViewed, "currently_viewed": currentPageIndex + 1, "total_screens": dataModel.fields?.count ?? 0] as [String : Any]
let params = [key_app_version : Bundle.main.oex_shortVersionString(), "total_viewed": pagesViewed, "currently_viewed": currentPageIndex + 1, "total_screens": dataModel.fields?.count ?? 0] as [String : Any]
environment.analytics.trackEvent(whatsNewEvent(name: AnalyticsEventName.WhatsNewClose.rawValue, displayName: "WhatsNew: Close"), forComponent: nil, withInfo: params)
}

private func logDoneEvent() {
let params = [key_app_version : Bundle.main.oex_buildVersionString(), "total_screens": dataModel.fields?.count ?? 0] as [String : Any]
let params = [key_app_version : Bundle.main.oex_shortVersionString(), "total_screens": dataModel.fields?.count ?? 0] as [String : Any]
environment.analytics.trackEvent(whatsNewEvent(name: AnalyticsEventName.WhatsNewDone.rawValue, displayName: "WhatsNew: Done"), forComponent: nil, withInfo: params)
}

Expand Down
2 changes: 1 addition & 1 deletion Test/OEXInterface+AppReviewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class OEXInterface_AppReviewTests: XCTestCase {

func testDefaultAppVersion() {
interface.saveAppVersionWhenLastRated()
XCTAssertEqual(interface.getSavedAppVersionWhenLastRated(), Bundle.main.oex_buildVersionString())
XCTAssertEqual(interface.getSavedAppVersionWhenLastRated(), Bundle.main.oex_shortVersionString())
}

func testCustomAppVersion() {
Expand Down

0 comments on commit 29a9817

Please sign in to comment.