Skip to content

Commit b2c51cf

Browse files
documentation
1 parent 533cb60 commit b2c51cf

5 files changed

Lines changed: 142 additions & 29 deletions

File tree

ABReleaseNotesViewController/ABReleaseNotesDownloader.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,30 @@
2626

2727
#import <Foundation/Foundation.h>
2828

29+
/**
30+
Retrieves release notes and the current version number from the App Store for the app whose
31+
app identifier is passed in on initialization.
32+
*/
33+
34+
NS_ASSUME_NONNULL_BEGIN
35+
2936
@interface ABReleaseNotesDownloader : NSObject
37+
38+
/**
39+
Returns a newly initialized downloader with the specified app identifier.
40+
41+
@param appIdentifier The unique ID of your app in the App Store.
42+
43+
@return A newly initialized `ABReleaseNotesDownloader` object.
44+
*/
3045
- (instancetype)initWithAppIdentifier:(NSString *)appIdentifier;
46+
47+
/**
48+
Responsible for checking the App Store for updates to the app identifier specified in initialization.
49+
50+
@param checker The block to execute after the update check finishes. This block has no return value, but has three parameters: a BOOL flag indicating whether the app has been updated, release notes, and a new version number. and takes no parameters.
51+
*/
3152
- (void)checkForUpdates:(void (^)(BOOL updated, NSString *releaseNotes, NSString *versionNumber))checker;
3253
@end
54+
55+
NS_ASSUME_NONNULL_END

ABReleaseNotesViewController/ABReleaseNotesPresentationController.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626

2727
#import <UIKit/UIKit.h>
2828

29+
/**
30+
A presentation controller used by `ABReleaseNotesViewController` to control the display of the
31+
release notes controller on screen. Designed to be used as-is, and you shouldn't have to interact
32+
directly with this class.
33+
*/
34+
2935
@interface ABReleaseNotesPresentationController : UIPresentationController
3036

3137
@end

ABReleaseNotesViewController/ABReleaseNotesViewController.h

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,74 @@
2525

2626
#import <UIKit/UIKit.h>
2727

28+
/**
29+
30+
Overview
31+
====
32+
33+
`ABReleaseNotesViewController` is a view controller, and should be the only part of this
34+
system with which you'll need to interact directly.
35+
36+
You should generally instantiate `ABReleaseNotesViewController` with the factory class method
37+
provided here, instead of calling one of the `-init` methods. However, you can call one of the
38+
`-init:` methods if you really want to, but take care to ensure that the properties set by the
39+
factory method are also set wherever you initialize your new view controller.
40+
41+
Notes:
42+
====
43+
44+
* There is no guarantee that your block in `-checkForUpdates:` will ever be called. Do not assume it will be.
45+
46+
Typical Usage
47+
====
48+
49+
Create your release notes object in your init method, or in `-viewDidLoad`:
50+
51+
- (void)viewDidLoad {
52+
[super viewDidLoad];
53+
self.releaseNotes = [ABReleaseNotesViewController releaseNotesControllerWithAppIdentifier:@"329380089" title:NSLocalizedString(@"Release Notes", @"")];
54+
}
55+
56+
After your view appears, begin checking for updates. If an update is available, you may present the view controller immediately, as depicted below:
57+
58+
[self.releaseNotes checkForUpdates:^(BOOL updated) {
59+
if (updated) {
60+
[self presentViewController:self.releaseNotes animated:YES completion:nil];
61+
}
62+
}];
63+
64+
Additionally, you could present an alert or some sort of non-modal user interface to the user informing them that they can read release notes if desired.
65+
*/
66+
67+
NS_ASSUME_NONNULL_BEGIN
68+
2869
@interface ABReleaseNotesViewController : UIViewController
70+
71+
/**
72+
The style of the blur effect to apply to your view's background.
73+
*/
2974
@property(nonatomic,assign) UIBlurEffectStyle blurEffectStyle;
75+
76+
/**
77+
The title of the close button at the bottom of the view. By default, this is "Dismiss".
78+
*/
3079
@property(nonatomic,copy) NSString *closeButtonTitle;
31-
@property(nonatomic,copy) UIColor *lineViewColor;
32-
+ (id)releaseNotesControllerWithAppIdentifier:(NSString *)appIdentifier title:(NSString*)title;
80+
81+
/**
82+
Creates and returns a new view controller.
83+
84+
@param appIdentifier The App Store identifier for your app.
85+
86+
@return A newly initialized ABReleaseNotesViewController
87+
*/
88+
- (instancetype)initWithAppIdentifier:(NSString*)appIdentifier;
89+
90+
/**
91+
Checks the App Store to see if the current version of the app is an updated version.
92+
93+
@param block The completion block called if an update has occurred.
94+
*/
3395
- (void)checkForUpdates:(void(^)(BOOL updated))block;
3496
@end
97+
98+
NS_ASSUME_NONNULL_END

ABReleaseNotesViewController/ABReleaseNotesViewController.m

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,45 +37,58 @@ @interface ABReleaseNotesViewController ()<UIViewControllerTransitioningDelegate
3737
@property(nonatomic,strong) UIVisualEffectView *vibrancyView;
3838
@property(nonatomic,strong) UILabel *titleLabel;
3939
@property(nonatomic,strong) UITextView *bodyText;
40+
@property(nonatomic,copy) UIColor *lineViewColor;
4041
@end
4142

4243
@implementation ABReleaseNotesViewController
4344

44-
#pragma mark - Initialization
45-
46-
- (instancetype)init {
45+
- (instancetype)initWithAppIdentifier:(NSString*)appIdentifier {
4746
self = [super init];
48-
47+
4948
if (self) {
50-
_blurEffectStyle = UIBlurEffectStyleLight;
51-
52-
_closeButtonTitle = NSLocalizedString(@"Dismiss", @"");
53-
54-
_lineViewColor = [UIColor colorWithWhite:0.f alpha:0.25f];
49+
self.title = NSLocalizedString(@"Release Notes", @"");
5550

56-
_bodyText = ({
57-
UITextView *textView = [[UITextView alloc] init];
58-
textView.translatesAutoresizingMaskIntoConstraints = NO;
59-
textView.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
60-
textView.backgroundColor = [UIColor clearColor];
61-
textView.editable = NO;
62-
textView.selectable = NO;
63-
textView;
64-
});
51+
_appIdentifier = [appIdentifier copy];
52+
[self commonInit];
6553
}
6654
return self;
6755
}
6856

69-
+ (id)releaseNotesControllerWithAppIdentifier:(NSString *)appIdentifier title:(NSString *)title {
57+
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
58+
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
59+
if (self) {
60+
[self commonInit];
61+
}
62+
return self;
63+
}
7064

71-
ABReleaseNotesViewController *controller = [[ABReleaseNotesViewController alloc] init];
72-
controller.title = title;
73-
controller.appIdentifier = appIdentifier;
74-
controller.blurEffectStyle = UIBlurEffectStyleLight;
75-
controller.modalPresentationStyle = UIModalPresentationCustom;
76-
controller.transitioningDelegate = controller;
65+
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
66+
self = [super initWithCoder:aDecoder];
67+
68+
if (self) {
69+
[self commonInit];
70+
}
71+
return self;
72+
}
7773

78-
return controller;
74+
- (void)commonInit {
75+
_blurEffectStyle = UIBlurEffectStyleLight;
76+
self.modalPresentationStyle = UIModalPresentationCustom;
77+
self.transitioningDelegate = self;
78+
79+
_closeButtonTitle = NSLocalizedString(@"Dismiss", @"");
80+
81+
_lineViewColor = [UIColor colorWithWhite:0.f alpha:0.25f];
82+
83+
_bodyText = ({
84+
UITextView *textView = [[UITextView alloc] init];
85+
textView.translatesAutoresizingMaskIntoConstraints = NO;
86+
textView.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
87+
textView.backgroundColor = [UIColor clearColor];
88+
textView.editable = NO;
89+
textView.selectable = NO;
90+
textView;
91+
});
7992
}
8093

8194
#pragma mark - UIViewController
@@ -149,6 +162,13 @@ - (void)close {
149162
#pragma mark - Public Methods
150163

151164
- (void)checkForUpdates:(void(^)(BOOL updated))block {
165+
166+
BOOL hasIdentifier = self.appIdentifier.length > 0;
167+
NSParameterAssert(hasIdentifier);
168+
if (!hasIdentifier) {
169+
return;
170+
}
171+
152172
NSString *defaultsAppVersion = [[NSUserDefaults standardUserDefaults] objectForKey:ABReleaseNotesVersionUserDefaultsKey];
153173
if (!defaultsAppVersion) {
154174
// it's nil, so write out a value first launch and bail.

Demo/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ - (void)viewDidLoad {
2626
[self.view addSubview:self.webView];
2727
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]]];
2828

29-
self.releaseNotes = [ABReleaseNotesViewController releaseNotesControllerWithAppIdentifier:@"329380089" title:NSLocalizedString(@"Release Notes", @"")];
29+
self.releaseNotes = [[ABReleaseNotesViewController alloc] initWithAppIdentifier:@"329380089"];
3030
}
3131

3232
- (void)viewDidAppear:(BOOL)animated {

0 commit comments

Comments
 (0)