Skip to content

Commit

Permalink
Merge pull request ResearchKit#48 from syoung-smallwisdom/syoung-develop
Browse files Browse the repository at this point in the history
BRIDGE-652 Default handling of unsupported app version in AppCore
  • Loading branch information
Erin-Mounts committed Dec 1, 2015
2 parents a865cf6 + 4189feb commit b8e3091
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 37 deletions.
2 changes: 1 addition & 1 deletion APCAppCore/APCAppCore/Consent/APCConsentBooleanQuestion.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ - (instancetype)initWithIdentifier:(NSString*)identifier prompt:(NSString*)promp

- (BOOL)evaluate:(ORKStepResult*)stepResult
{
ORKBooleanQuestionResult* questionResult = stepResult.results.firstObject;
ORKBooleanQuestionResult* _Nullable questionResult = stepResult.results.firstObject;
BOOL evaulationResult = false;

if ([questionResult isKindOfClass:[ORKBooleanQuestionResult class]])
Expand Down
18 changes: 8 additions & 10 deletions APCAppCore/APCAppCore/Consent/APCConsentTextChoiceQuestion.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ - (instancetype)initWithIdentifier:(NSString*)identifier

- (BOOL)evaluate:(ORKStepResult*)stepResult
{
ORKChoiceQuestionResult* questionResult = stepResult.results.firstObject;
BOOL evaulationResult = false;
ORKChoiceQuestionResult* _Nullable questionResult = (ORKChoiceQuestionResult*)stepResult.results.firstObject;
BOOL evaulationResult = false;

if ([questionResult isKindOfClass:[ORKChoiceQuestionResult class]])
if ([questionResult isKindOfClass:[ORKChoiceQuestionResult class]]
&& questionResult.choiceAnswers != nil && questionResult.choiceAnswers.count > 0)
{
if (questionResult != nil && questionResult.choiceAnswers != nil && questionResult.choiceAnswers.count > 0)
{
NSString* answer = questionResult.choiceAnswers.firstObject;
NSUInteger index = [self.answers indexOfObject:answer];

evaulationResult = index == self.indexOfExpectedAnswer;
}
NSString* answer = questionResult.choiceAnswers.firstObject;
NSUInteger index = [self.answers indexOfObject:answer];

evaulationResult = (index == self.indexOfExpectedAnswer);
}

return evaulationResult;
Expand Down
6 changes: 3 additions & 3 deletions APCAppCore/APCAppCore/Library/Categories/NSError+Bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ - (NSString*)bridgeErrorMessage
{
message = kAPCServerBusyErrorMessage;
}
else if ([code isEqual: @(kSBBInternetNotConnected)])
else if ([code isEqual: @(SBBErrorCodeInternetNotConnected)])
{
message = kAPCNotConnectedErrorMessage;
}
else if ([code isEqual:@(kSBBServerNotReachable)])
else if ([code isEqual:@(SBBErrorCodeServerNotReachable)])
{
message = kAPCNotReachableErrorMessage;
}
else if ([code isEqual:@(kSBBServerUnderMaintenance)])
else if ([code isEqual:@(SBBErrorCodeServerUnderMaintenance)])
{
message = kAPCServerUnderMaintanenceErrorMessage;
}
Expand Down
7 changes: 6 additions & 1 deletion APCAppCore/APCAppCore/Startup/APCAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static NSString* const kDatabaseName = @"db.sqlite";

@class APCDataSubstrate, APCDataMonitor, APCScheduler, APCPasscodeViewController, APCTasksReminderManager, APCPassiveDataCollector, APCFitnessAllocation;

@interface APCAppDelegate : UIResponder <UIApplicationDelegate, APCOnboardingManagerProvider, APCPasscodeViewControllerDelegate>
@interface APCAppDelegate : UIResponder <UIApplicationDelegate, APCOnboardingManagerProvider, APCPasscodeViewControllerDelegate, SBBBridgeAppDelegate>

@property (nonatomic, strong) APCFitnessAllocation *sevenDayFitnessAllocationData;
@property (strong, nonatomic) UITabBarController *tabBarController;
Expand Down Expand Up @@ -79,6 +79,11 @@ static NSString* const kDatabaseName = @"db.sqlite";

- (NSString*) certificateFileName;

/**
* link for opening the app store. AppDelegate implementations can override.
*/
- (NSURL *)appStoreLinkURL;

//Show Methods
- (void) showTabBar;
- (void) showOnBoarding;
Expand Down
52 changes: 44 additions & 8 deletions APCAppCore/APCAppCore/Startup/APCAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#import "APCDemographicUploader.h"
#import "APCConstants.h"
#import "APCUtilities.h"
#import "APCCatastrophicErrorViewController.h"

#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
Expand Down Expand Up @@ -618,24 +619,59 @@ - (BOOL) hadCatastrophicStartupError
}

- (void) showCatastrophicStartupError
{
[self showCatastrophicStartupErrorWithMessage:nil buttonTitle:nil action:nil];
}

- (void) showCatastrophicStartupErrorWithMessage:(NSString *)message
buttonTitle:(NSString *)buttonTitle
action:(void(^)(void))action
{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName: @"CatastrophicError"
bundle: [NSBundle appleCoreBundle]];

UIViewController *errorViewController = [storyBoard instantiateInitialViewController];
APCCatastrophicErrorViewController *errorViewController = (APCCatastrophicErrorViewController*)[storyBoard instantiateInitialViewController];

errorViewController.message = message;
errorViewController.buttonTitle = buttonTitle;
errorViewController.buttonAction = action;

self.window.rootViewController = errorViewController;
NSError *error = self.catastrophicStartupError;

if (message.length == 0) {

NSError *error = self.catastrophicStartupError;
__block APCAppDelegate *blockSafeSelf = self;

[[NSOperationQueue mainQueue] addOperationWithBlock:^{

__block APCAppDelegate *blockSafeSelf = self;
UIAlertController *alert = [UIAlertController simpleAlertWithTitle: error.userInfo [NSLocalizedFailureReasonErrorKey]
message: error.userInfo [NSLocalizedRecoverySuggestionErrorKey]];

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[blockSafeSelf.window.rootViewController presentViewController: alert animated: YES completion: nil];
}];
}
}

UIAlertController *alert = [UIAlertController simpleAlertWithTitle: error.userInfo [NSLocalizedFailureReasonErrorKey]
message: error.userInfo [NSLocalizedRecoverySuggestionErrorKey]];
/*********************************************************************************/
#pragma mark - Unsupported App Version
/*********************************************************************************/
- (BOOL)handleUnsupportedAppVersionError:(NSError*)error networkManager:(id __unused)networkManager
{
NSString *localizedButtonTitle = NSLocalizedStringWithDefaultValue(@"APC_BUTTON_TITLE_GOTO_APP_STORE", @"APCAppCore", APCBundle(), @"Open App Store", @"Button title: Open App Store");
self.catastrophicStartupError = error;

[self showCatastrophicStartupErrorWithMessage:[error localizedDescription]
buttonTitle:localizedButtonTitle
action:^{
[[UIApplication sharedApplication] openURL:[self appStoreLinkURL]];
}];
return YES;
}

[blockSafeSelf.window.rootViewController presentViewController: alert animated: YES completion: nil];
}];
- (NSURL *)appStoreLinkURL
{
return [[NSBundle mainBundle] appStoreLinkURL];
}

/*********************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@

@interface APCCatastrophicErrorViewController : UIViewController

@property (nonatomic) NSString * _Nullable message;
@property (nonatomic) NSString * _Nullable buttonTitle;
@property (nonatomic, copy) void (^ _Nullable buttonAction)(void);

@end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// APCCatastrophicErrorViewController.m
// APCAppCore
//
Expand Down Expand Up @@ -36,6 +36,8 @@

@interface APCCatastrophicErrorViewController ()
@property (weak, nonatomic) IBOutlet UILabel *appNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *optionalMessageLabel;
@property (weak, nonatomic) IBOutlet UIButton *optionalActionButton;
@end

@implementation APCCatastrophicErrorViewController
Expand All @@ -47,4 +49,30 @@ - (void) viewDidLoad
self.appNameLabel.text = [APCUtilities appName];
}

- (void)setMessage:(NSString *)message
{
_message = message;
dispatch_async(dispatch_get_main_queue(), ^{
self.optionalMessageLabel.text = message;
self.optionalMessageLabel.hidden = (message.length == 0);
});
}

- (void)setButtonTitle:(NSString *)buttonTitle
{
_buttonTitle = buttonTitle;
dispatch_async(dispatch_get_main_queue(), ^{
[self.optionalActionButton setTitle:buttonTitle forState:UIControlStateNormal];
self.optionalActionButton.hidden = (buttonTitle.length == 0);
});
}

- (IBAction)buttonTapped:(id __unused)sender
{
if (self.buttonAction) {
self.buttonAction();
}
}


@end
37 changes: 33 additions & 4 deletions APCAppCore/APCAppCore/UI/Errors/CatastrophicError.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="yja-Bm-gxs">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="14F1021" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="yja-Bm-gxs">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
Expand All @@ -22,26 +22,55 @@
<rect key="frame" x="270" y="39" width="61" height="57"/>
<animations/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DZ6-lI-FWU">
<rect key="frame" x="16" y="104" width="568" height="21"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DZ6-lI-FWU">
<rect key="frame" x="20" y="104" width="560" height="20.5"/>
<animations/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QhP-HV-IHQ">
<rect key="frame" x="160" y="248" width="280" height="103.5"/>
<constraints>
<constraint firstAttribute="width" priority="800" constant="280" id="KrH-S9-Rc0"/>
</constraints>
<string key="text">Optional Error Message: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur blandit odio vel felis facilisis imperdiet. Mauris aliquam tempor ex ac.</string>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jYX-V4-Uu8">
<rect key="frame" x="274.5" y="369.5" width="51" height="32"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<state key="normal" title="Button"/>
<connections>
<action selector="buttonTapped:" destination="yja-Bm-gxs" eventType="touchUpInside" id="bXn-CM-IDh"/>
</connections>
</button>
</subviews>
<animations/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="DZ6-lI-FWU" firstAttribute="leading" secondItem="QnL-3e-ykA" secondAttribute="leadingMargin" id="6b2-m9-hGJ"/>
<constraint firstItem="QhP-HV-IHQ" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="QnL-3e-ykA" secondAttribute="leadingMargin" constant="8" id="AJ1-zH-1fC"/>
<constraint firstAttribute="centerX" secondItem="Y2i-gN-3s8" secondAttribute="centerX" id="Fkt-Ky-GdA"/>
<constraint firstItem="jYX-V4-Uu8" firstAttribute="centerX" secondItem="QnL-3e-ykA" secondAttribute="centerX" id="NwT-eU-yLs"/>
<constraint firstItem="bJ4-mh-qzW" firstAttribute="top" relation="greaterThanOrEqual" secondItem="QhP-HV-IHQ" secondAttribute="bottom" constant="8" id="PYW-Q5-fTm"/>
<constraint firstItem="jYX-V4-Uu8" firstAttribute="top" secondItem="QhP-HV-IHQ" secondAttribute="bottom" constant="18" id="Wkp-Zo-eyv"/>
<constraint firstItem="QhP-HV-IHQ" firstAttribute="top" relation="greaterThanOrEqual" secondItem="DZ6-lI-FWU" secondAttribute="bottom" constant="16" id="Zdo-BQ-2el"/>
<constraint firstItem="DZ6-lI-FWU" firstAttribute="trailing" secondItem="QnL-3e-ykA" secondAttribute="trailingMargin" id="ZzB-ys-no3"/>
<constraint firstItem="QhP-HV-IHQ" firstAttribute="centerY" secondItem="QnL-3e-ykA" secondAttribute="centerY" priority="750" id="cWR-ZQ-yLs"/>
<constraint firstItem="bJ4-mh-qzW" firstAttribute="top" relation="greaterThanOrEqual" secondItem="jYX-V4-Uu8" secondAttribute="bottom" constant="16" id="cib-XY-cLb"/>
<constraint firstItem="Y2i-gN-3s8" firstAttribute="top" secondItem="Iwy-1O-5KB" secondAttribute="bottom" constant="19" id="dxT-vr-XbX"/>
<constraint firstAttribute="trailingMargin" relation="greaterThanOrEqual" secondItem="QhP-HV-IHQ" secondAttribute="trailing" constant="8" id="gT2-wY-r3u"/>
<constraint firstItem="DZ6-lI-FWU" firstAttribute="top" secondItem="Y2i-gN-3s8" secondAttribute="bottom" constant="8" id="geZ-PB-QJw"/>
<constraint firstItem="QhP-HV-IHQ" firstAttribute="centerX" secondItem="QnL-3e-ykA" secondAttribute="centerX" id="j4T-VZ-ryG"/>
</constraints>
</view>
<connections>
<outlet property="appNameLabel" destination="DZ6-lI-FWU" id="I3e-dv-tr5"/>
<outlet property="optionalActionButton" destination="jYX-V4-Uu8" id="pzf-h0-Bp6"/>
<outlet property="optionalMessageLabel" destination="QhP-HV-IHQ" id="4RO-OV-IGE"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="M2r-8I-gl1" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ - (void)studyVideoCollectionViewCellReadConsent:(APCStudyVideoCollectionViewCell

UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:webViewController];
[self.navigationController presentViewController:navController animated:YES completion:^{
[webViewController.webView loadData:[self PDFDataOfConsent] MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
[webViewController.webView loadData:[self PDFDataOfConsent] MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:[NSURL URLWithString:@"http://"]];
}];

}
Expand Down Expand Up @@ -459,7 +459,7 @@ - (void)studyLandingCollectionViewCellReadConsent:(APCStudyLandingCollectionView

UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:webViewController];
[self.navigationController presentViewController:navController animated:YES completion:^{
[webViewController.webView loadData:[self PDFDataOfConsent] MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
[webViewController.webView loadData:[self PDFDataOfConsent] MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:[NSURL URLWithString:@"http://"]];
}];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ - (void) handleSigninResponseWithError: (NSError *) error
{
if (error)
{
if (error.code == kSBBServerPreconditionNotMet)
if (error.code == SBBErrorCodeServerPreconditionNotMet)
{
[self getServerConsent];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ - (void) signIn
if (error) {
APCLogError2 (error);

if (error.code == kSBBServerPreconditionNotMet) {
if (error.code == SBBErrorCodeServerPreconditionNotMet) {
[self showConsent];
} else {
NSString *errorMessage = [error message];
Expand All @@ -193,7 +193,7 @@ - (void) signIn
if (error) {
APCLogError2 (error);

if (error.code == kSBBServerPreconditionNotMet) {
if (error.code == SBBErrorCodeServerPreconditionNotMet) {
[self showConsent];
} else {
UIAlertController *alert = [UIAlertController simpleAlertWithTitle:NSLocalizedStringWithDefaultValue(@"Sign In", @"APCAppCore", APCBundle(), @"Sign In", @"") message:error.message];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ - (IBAction)next

APCLogError2 (error);

if (error.code == kSBBInternetNotConnected || error.code == kSBBServerNotReachable || error.code == kSBBServerUnderMaintenance) {
if (error.code == SBBErrorCodeInternetNotConnected || error.code == SBBErrorCodeServerNotReachable || error.code == SBBErrorCodeServerUnderMaintenance) {
[spinnerController dismissViewControllerAnimated:NO completion:^{

UIAlertController *alertView = [UIAlertController alertControllerWithTitle:NSLocalizedStringWithDefaultValue(@"Sign Up", @"APCAppCore", APCBundle(), @"Sign Up", @"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ - (void)reviewConsent

UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:webViewController];
[weakSelf.navigationController presentViewController:navController animated:YES completion:^{
[webViewController.webView loadData:data MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
[webViewController.webView loadData:data MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:[NSURL URLWithString:@"http://"]];
}];

}];
Expand Down

0 comments on commit b8e3091

Please sign in to comment.