Skip to content

Commit a929e2c

Browse files
Add a mode property for switching the controller between 'testing' (where the controller always appears), and 'production' (where it only appears if there's an update)
1 parent b2c51cf commit a929e2c

2 files changed

Lines changed: 34 additions & 16 deletions

File tree

ABReleaseNotesViewController/ABReleaseNotesViewController.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,20 @@
6666

6767
NS_ASSUME_NONNULL_BEGIN
6868

69+
typedef NS_ENUM(NSUInteger, ABReleaseNotesViewControllerMode) {
70+
ABReleaseNotesViewControllerModeTesting = 0,
71+
ABReleaseNotesViewControllerModeProduction
72+
};
73+
6974
@interface ABReleaseNotesViewController : UIViewController
7075

76+
/**
77+
The `mode` property controls whether the release notes controller always
78+
appears for testing purposes, or whether it only appears when an update
79+
has actually occurred. By default, this is set to `ABReleaseNotesViewControllerModeTesting`
80+
*/
81+
@property(nonatomic,assign) ABReleaseNotesViewControllerMode mode;
82+
7183
/**
7284
The style of the blur effect to apply to your view's background.
7385
*/

ABReleaseNotesViewController/ABReleaseNotesViewController.m

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,13 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder {
7272
}
7373

7474
- (void)commonInit {
75-
_blurEffectStyle = UIBlurEffectStyleLight;
7675
self.modalPresentationStyle = UIModalPresentationCustom;
7776
self.transitioningDelegate = self;
78-
77+
78+
_mode = ABReleaseNotesViewControllerModeTesting;
79+
80+
_blurEffectStyle = UIBlurEffectStyleLight;
81+
7982
_closeButtonTitle = NSLocalizedString(@"Dismiss", @"");
8083

8184
_lineViewColor = [UIColor colorWithWhite:0.f alpha:0.25f];
@@ -109,7 +112,9 @@ - (void)viewDidLoad {
109112
[self createVisualEffectsViews];
110113

111114
UINavigationBar *navigationBar = [[UINavigationBar alloc] init];
112-
[navigationBar pushNavigationItem:[[UINavigationItem alloc] initWithTitle:self.title] animated:YES];
115+
116+
NSString *title = self.mode == ABReleaseNotesViewControllerModeProduction ? self.title : [NSString stringWithFormat:@"TESTING - %@", self.title];
117+
[navigationBar pushNavigationItem:[[UINavigationItem alloc] initWithTitle:title] animated:YES];
113118

114119
UIView *bottomEdge = [self.class makeLineViewWithColor:self.lineViewColor];
115120

@@ -168,24 +173,25 @@ - (void)checkForUpdates:(void(^)(BOOL updated))block {
168173
if (!hasIdentifier) {
169174
return;
170175
}
171-
172-
NSString *defaultsAppVersion = [[NSUserDefaults standardUserDefaults] objectForKey:ABReleaseNotesVersionUserDefaultsKey];
173-
if (!defaultsAppVersion) {
174-
// it's nil, so write out a value first launch and bail.
175-
[[NSUserDefaults standardUserDefaults] setObject:[self.class appVersionNumber] forKey:ABReleaseNotesVersionUserDefaultsKey];
176-
return;
177-
}
178176

179-
// TODO: put me back!
180-
// if ([defaultsAppVersion isEqual:[self.class appVersionNumber]]) {
181-
// // no new app version installed since last launch.
182-
// return;
183-
// }
177+
if (self.mode == ABReleaseNotesViewControllerModeProduction) {
178+
NSString *defaultsAppVersion = [[NSUserDefaults standardUserDefaults] objectForKey:ABReleaseNotesVersionUserDefaultsKey];
179+
if (!defaultsAppVersion) {
180+
// it's nil, so write out a value first launch and bail.
181+
[[NSUserDefaults standardUserDefaults] setObject:[self.class appVersionNumber] forKey:ABReleaseNotesVersionUserDefaultsKey];
182+
return;
183+
}
184+
185+
if ([defaultsAppVersion isEqual:[self.class appVersionNumber]]) {
186+
// no new app version installed since last launch.
187+
return;
188+
}
189+
}
184190

185191
// If we've gotten this far, then there's seemingly an update to tell the user about.
186192
self.downloader = [[ABReleaseNotesDownloader alloc] initWithAppIdentifier:self.appIdentifier];
187193
[self.downloader checkForUpdates:^(BOOL updated, NSString *releaseNotes, NSString *versionNumber) {
188-
if ([versionNumber isEqual:[self.class appVersionNumber]]) {
194+
if (self.mode == ABReleaseNotesViewControllerModeProduction && [versionNumber isEqual:[self.class appVersionNumber]]) {
189195
// Belt and suspenders in case something went wrong.
190196
NSLog(@"We downloaded release notes, but the version in the App Store is identical to our local version!");
191197
NSLog(@"Local: %@ - App Store: %@", [self.class appVersionNumber], versionNumber);

0 commit comments

Comments
 (0)