Skip to content

Commit

Permalink
v1.2 - Moved to Storyboard, release Notes from App Store, renaming an…
Browse files Browse the repository at this point in the history
…d improvements.
  • Loading branch information
Ashley Richards committed Mar 20, 2017
1 parent 4987e31 commit 1e150fd
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 207 deletions.
9 changes: 4 additions & 5 deletions ARWhatsNew/ARWhatsNew.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@

@interface ARWhatsNew : UIViewController
// Background color
@property UIColor *primaryColor;
@property UIColor *backgroundColor;
// Button background color
@property UIColor *secondaryColor;
@property UIColor *dismissButtonColor;
// Show the Release Notes
@property NSString *releaseNotes;
// Change default for button instade of 'Get Started'.
@property NSString *acceptButtonText;
@property NSString *dismissButtonText;
// Disable "Get Started" button from being disabled until user scrolls to bottom.
@property BOOL disableReadAllRequired;
// Determine to show modal for x.x or x.x.x
@property BOOL majorReleasesOnly;

-(void)resetWhatsNew;
-(NSString*)appVersion;
-(void)showWhatsNew;
-(BOOL)userNotSeenWhatsNew;

@end
78 changes: 57 additions & 21 deletions ARWhatsNew/ARWhatsNew.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ @interface ARWhatsNew ()
@property IBOutlet UILabel *labelInVersion;
@property IBOutlet UILabel *labelReleaseNotes;
@property IBOutlet UITextView *textViewNotes;
@property IBOutlet UIButton *acceptButton;
@property IBOutlet UIButton *dismissButton;

@end

Expand All @@ -30,18 +30,18 @@ -(instancetype)init {
-(void)viewDidLoad {
[super viewDidLoad];

if (self.primaryColor != nil) {
self.view.backgroundColor = self.primaryColor;
if (self.backgroundColor != nil) {
self.view.backgroundColor = self.backgroundColor;
}
if (self.secondaryColor != nil) {
self.acceptButton.backgroundColor = self.secondaryColor;
if (self.dismissButtonColor != nil) {
self.dismissButton.backgroundColor = self.dismissButtonColor;
}

self.labelWhatsNew.textColor = [self readableForegroundColorForBackgroundColor:self.primaryColor];
self.labelInVersion.textColor = [self readableForegroundColorForBackgroundColor:self.primaryColor];
self.labelReleaseNotes.textColor = [self readableForegroundColorForBackgroundColor:self.primaryColor];
self.textViewNotes.textColor = [self readableForegroundColorForBackgroundColor:self.primaryColor];
[self.acceptButton setTitleColor:[self readableForegroundColorForBackgroundColor:self.secondaryColor]
self.labelWhatsNew.textColor = [self readableForegroundColorForBackgroundColor:self.backgroundColor];
self.labelInVersion.textColor = [self readableForegroundColorForBackgroundColor:self.backgroundColor];
self.labelReleaseNotes.textColor = [self readableForegroundColorForBackgroundColor:self.backgroundColor];
self.textViewNotes.textColor = [self readableForegroundColorForBackgroundColor:self.backgroundColor];
[self.dismissButton setTitleColor:[self readableForegroundColorForBackgroundColor:self.dismissButtonColor]
forState:UIControlStateNormal];

self.textViewNotes.font = [UIFont systemFontOfSize:17];
Expand All @@ -52,21 +52,53 @@ -(void)viewDidLoad {
NSString *ver = [NSString stringWithFormat:@"IN VERSION %@", [self appVersion]];
[self.labelInVersion setText:NSLocalizedString(ver, nil)];

// Set and localise release notes in textView
[self.textViewNotes setText:NSLocalizedString(self.releaseNotes,)];
// Set and localise release notes in textView.
// Check if hardcoded releaseNotes were supplied.
if (self.releaseNotes != nil) {
// If there is a hardcoded string then show that.
[self.textViewNotes setText:NSLocalizedString(self.releaseNotes,)];

[[NSUserDefaults standardUserDefaults] setObject:NSLocalizedString(self.releaseNotes,) forKey:@"ARWhatsNewReleaseNotes"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
// Check if there are already existing release notes stored on device.
else if ([[NSUserDefaults standardUserDefaults] objectForKey:@"ARWhatsNewReleaseNotes"] != nil) {
// Load saved release notes into view.
[self.textViewNotes setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"ARWhatsNewReleaseNotes"]];
}else {
// If releaseNotes was not provided then get release notes from
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString* appID = infoDictionary[@"CFBundleIdentifier"];
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];
NSData* data = [NSData dataWithContentsOfURL:url];
NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

if ([lookup[@"resultCount"] integerValue] == 1){
// Set and localise release notes in textView
NSString *storeReleaseNotes = lookup[@"results"][0][@"releaseNotes"];

[self.textViewNotes setText:NSLocalizedString(storeReleaseNotes,)];
[[NSUserDefaults standardUserDefaults] setObject:storeReleaseNotes forKey:@"ARWhatsNewReleaseNotes"];
[[NSUserDefaults standardUserDefaults] synchronize];

} else {
// If no app was found with the BundleID of project then show error message.
[self.textViewNotes setText:NSLocalizedString(@"App not available on the App Store.\n\nPlease contact the developer.",)];
}
}

// Accept button
if (self.acceptButtonText != nil) {
if (self.dismissButtonText != nil) {
// Change acceptButtonText title to determinted string
[self.acceptButton setTitle:NSLocalizedString(self.acceptButtonText,)
[self.dismissButton setTitle:NSLocalizedString(self.dismissButtonText,)
forState:UIControlStateNormal];
} else {
// Set acceptButtonText to default string
[self.acceptButton setTitle:NSLocalizedString(@"GET STARTED",)
[self.dismissButton setTitle:NSLocalizedString(@"GET STARTED",)
forState:UIControlStateNormal];
}

[self.acceptButton setEnabled:self.disableReadAllRequired];
[self.dismissButton setEnabled:!self.disableReadAllRequired];
}

-(IBAction)GetStarted:(id)sender {
Expand All @@ -81,6 +113,7 @@ -(IBAction)GetStarted:(id)sender {
-(void)resetWhatsNew {
NSString *verString = [NSString stringWithFormat:@"whatsNew_%@", [self appVersion]];

[[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"ARWhatsNewReleaseNotes"];
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:verString];
[[NSUserDefaults standardUserDefaults] synchronize];
}
Expand All @@ -93,7 +126,7 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height;
// AcceptButtonText is disabled until user reads the entire version log unless disableReadAllRequired is set to YES
if (bottomEdge >= scrollView.contentSize.height) {
[self.acceptButton setEnabled:YES];
[self.dismissButton setEnabled:YES];
}
}

Expand All @@ -119,7 +152,7 @@ -(NSString *)appVersion {
return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
}

-(void)showWhatsNew {
-(BOOL)userNotSeenWhatsNew {
// Get number of . in version number
NSUInteger numberOfOccurrences = [[self.appVersion componentsSeparatedByString:@"."] count] - 1;

Expand All @@ -130,13 +163,16 @@ -(void)showWhatsNew {
// Check if majorRelesesOnly is enabled
if (self.majorReleasesOnly && (int)numberOfOccurrences == 1) {
// Check if only one . is detected
// Present modal
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:self animated:YES completion:nil];
return YES;
}

if (!self.majorReleasesOnly) {
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:self animated:YES completion:nil];
return YES;
} else {
return NO;
}
} else {
return NO;
}
}

Expand Down
109 changes: 109 additions & 0 deletions ARWhatsNew/ARWhatsNew.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Whats New-->
<scene sceneID="2fa-Vz-V7h">
<objects>
<viewController storyboardIdentifier="WhatsNew" id="nka-P9-byo" customClass="ARWhatsNew" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="ucf-1i-pgT"/>
<viewControllerLayoutGuide type="bottom" id="18m-Az-eSO"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="QRy-05-gGp">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="WHATS NEW" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JUg-md-Hca">
<rect key="frame" x="16" y="21" width="343" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="BWc-v0-qNk"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="heavy" pointSize="42"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="MAT-3z-04K">
<rect key="frame" x="0.0" y="612" width="375" height="55"/>
<color key="backgroundColor" red="0.1220189258" green="0.57733255620000001" blue="0.84165352579999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="55" id="ntH-gs-UBh"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="heavy" pointSize="22"/>
<state key="normal" title="GET STARTED">
<color key="titleColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<state key="disabled">
<color key="titleColor" red="0.14122495060000001" green="0.1247994229" blue="0.12983161209999999" alpha="0.2471104452" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="GetStarted:" destination="nka-P9-byo" eventType="touchUpInside" id="bj2-nT-AZg"/>
</connections>
</button>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="RELEASE NOTES" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="H3e-Jj-W7b">
<rect key="frame" x="16" y="110" width="343" height="33"/>
<constraints>
<constraint firstAttribute="height" constant="33" id="CdZ-Ye-OoP"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="heavy" pointSize="20"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" indicatorStyle="white" editable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iqh-Di-add">
<rect key="frame" x="16" y="143" width="344" height="460"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" weight="light" pointSize="18"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
<connections>
<outlet property="delegate" destination="nka-P9-byo" id="fpY-G0-KBd"/>
</connections>
</textView>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="IN VERSION" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VHa-mh-XqL">
<rect key="frame" x="16" y="67" width="343" height="24"/>
<fontDescription key="fontDescription" type="system" weight="heavy" pointSize="20"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.1448488235" green="0.65408736469999995" blue="0.94786173110000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="VHa-mh-XqL" firstAttribute="leading" secondItem="H3e-Jj-W7b" secondAttribute="leading" id="Ax5-Hk-CoO"/>
<constraint firstItem="JUg-md-Hca" firstAttribute="centerX" secondItem="iqh-Di-add" secondAttribute="centerX" id="IWL-uP-vYl"/>
<constraint firstItem="MAT-3z-04K" firstAttribute="top" secondItem="iqh-Di-add" secondAttribute="bottom" constant="9" id="V3E-Y3-fLY"/>
<constraint firstItem="H3e-Jj-W7b" firstAttribute="top" secondItem="JUg-md-Hca" secondAttribute="bottom" constant="39" id="Wvr-1D-KnP"/>
<constraint firstItem="VHa-mh-XqL" firstAttribute="top" secondItem="QRy-05-gGp" secondAttribute="top" constant="67" id="bag-Fv-QsK"/>
<constraint firstAttribute="trailing" secondItem="H3e-Jj-W7b" secondAttribute="trailing" constant="16" id="ch9-y0-zxw"/>
<constraint firstItem="MAT-3z-04K" firstAttribute="leading" secondItem="QRy-05-gGp" secondAttribute="leading" id="duj-Q6-zys"/>
<constraint firstItem="iqh-Di-add" firstAttribute="leading" secondItem="QRy-05-gGp" secondAttribute="leadingMargin" id="ekz-6t-Sja"/>
<constraint firstItem="VHa-mh-XqL" firstAttribute="centerX" secondItem="iqh-Di-add" secondAttribute="centerX" id="fkE-gu-fqA"/>
<constraint firstItem="JUg-md-Hca" firstAttribute="centerX" secondItem="QRy-05-gGp" secondAttribute="centerX" id="g7H-cm-Jd6"/>
<constraint firstItem="VHa-mh-XqL" firstAttribute="leading" secondItem="QRy-05-gGp" secondAttribute="leading" constant="16" id="gBg-mG-mnH"/>
<constraint firstItem="JUg-md-Hca" firstAttribute="leading" secondItem="QRy-05-gGp" secondAttribute="leading" constant="16" id="gWc-rR-IGp"/>
<constraint firstItem="iqh-Di-add" firstAttribute="top" secondItem="H3e-Jj-W7b" secondAttribute="bottom" id="gja-bF-AQq"/>
<constraint firstItem="H3e-Jj-W7b" firstAttribute="top" secondItem="VHa-mh-XqL" secondAttribute="bottom" constant="19" id="h77-vk-k7k"/>
<constraint firstItem="JUg-md-Hca" firstAttribute="centerX" secondItem="MAT-3z-04K" secondAttribute="centerX" id="u3N-dq-R1s"/>
<constraint firstAttribute="bottom" secondItem="MAT-3z-04K" secondAttribute="bottom" id="yA2-lz-XsO"/>
</constraints>
</view>
<connections>
<outlet property="dismissButton" destination="MAT-3z-04K" id="jLG-xr-6hd"/>
<outlet property="labelInVersion" destination="VHa-mh-XqL" id="Gzo-cW-Ap2"/>
<outlet property="labelReleaseNotes" destination="H3e-Jj-W7b" id="jtg-Ky-NPN"/>
<outlet property="labelWhatsNew" destination="JUg-md-Hca" id="GpX-4f-CGg"/>
<outlet property="textViewNotes" destination="iqh-Di-add" id="4ak-o3-ZHS"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="yIG-1u-QAv" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="121" y="149"/>
</scene>
</scenes>
</document>
Loading

0 comments on commit 1e150fd

Please sign in to comment.