diff --git a/APCAppCore/APCAppCore.xcodeproj/project.pbxproj b/APCAppCore/APCAppCore.xcodeproj/project.pbxproj index fc1ab74b..91e3be36 100644 --- a/APCAppCore/APCAppCore.xcodeproj/project.pbxproj +++ b/APCAppCore/APCAppCore.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 0595C6611C84292700210852 /* APCLocalJSONParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 0595C65F1C84292700210852 /* APCLocalJSONParser.h */; }; + 0595C6621C84292700210852 /* APCLocalJSONParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 0595C6601C84292700210852 /* APCLocalJSONParser.m */; }; 08023C4F1AA94F48008E6DDA /* APCAllSetContentViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 08023C4D1AA94F48008E6DDA /* APCAllSetContentViewController.h */; }; 08023C501AA94F48008E6DDA /* APCAllSetContentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 08023C4E1AA94F48008E6DDA /* APCAllSetContentViewController.m */; }; 08023C531AAA12DF008E6DDA /* APCAllSetTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 08023C511AAA12DF008E6DDA /* APCAllSetTableViewCell.h */; }; @@ -777,6 +779,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 0595C65F1C84292700210852 /* APCLocalJSONParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APCLocalJSONParser.h; sourceTree = ""; }; + 0595C6601C84292700210852 /* APCLocalJSONParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APCLocalJSONParser.m; sourceTree = ""; }; 08023C4D1AA94F48008E6DDA /* APCAllSetContentViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APCAllSetContentViewController.h; sourceTree = ""; }; 08023C4E1AA94F48008E6DDA /* APCAllSetContentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APCAllSetContentViewController.m; sourceTree = ""; }; 08023C511AAA12DF008E6DDA /* APCAllSetTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APCAllSetTableViewCell.h; sourceTree = ""; }; @@ -1577,6 +1581,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 0595C65E1C8428FA00210852 /* LocalJSONParser */ = { + isa = PBXGroup; + children = ( + 0595C65F1C84292700210852 /* APCLocalJSONParser.h */, + 0595C6601C84292700210852 /* APCLocalJSONParser.m */, + ); + path = LocalJSONParser; + sourceTree = ""; + }; 08027A3A1A7319AC00B358CC /* Assets */ = { isa = PBXGroup; children = ( @@ -2424,6 +2437,7 @@ F5B947341A73272C0034C522 /* Library */ = { isa = PBXGroup; children = ( + 0595C65E1C8428FA00210852 /* LocalJSONParser */, 5B0601BF1AE79AE0009D6D65 /* FeedParser */, F5B947351A73272C0034C522 /* AppearanceHelpers */, F5B9473C1A73272C0034C522 /* AssertionHandler */, @@ -3402,6 +3416,7 @@ F5F12AD21A2F78490015982C /* APCAddressTableViewCell.h in Headers */, F5F12ADC1A2F78490015982C /* APCSegmentedTableViewCell.h in Headers */, F5F129E21A2F78490015982C /* APCDataMonitor+Bridge.h in Headers */, + 0595C6611C84292700210852 /* APCLocalJSONParser.h in Headers */, F5B947D31A73272C0034C522 /* UIScrollView+Helper.h in Headers */, F5F12A811A2F78490015982C /* APCPresentAnimator.h in Headers */, F5B9462B1A7309A20034C522 /* ZZConstants.h in Headers */, @@ -3882,6 +3897,7 @@ F5B947C61A73272C0034C522 /* NSManagedObject+APCHelper.m in Sources */, F5B947DC1A73272C0034C522 /* APCLog.m in Sources */, 08023C501AA94F48008E6DDA /* APCAllSetContentViewController.m in Sources */, + 0595C6621C84292700210852 /* APCLocalJSONParser.m in Sources */, F5F12AD31A2F78490015982C /* APCAddressTableViewCell.m in Sources */, F5F12A701A2F78490015982C /* APCCircularProgressView.m in Sources */, 5B827B611A81CAE200C685A3 /* APCDashboardTableViewCell.m in Sources */, @@ -3895,7 +3911,6 @@ F5B9480D1A73272C0034C522 /* APCScheduleExpressionTokenizer.m in Sources */, 6C7346091A7ECD3B00DA9CD8 /* APCConsentTaskViewController.m in Sources */, EE64F4321B02517000A402A7 /* APCOnboardingManager.m in Sources */, - F54DDD281A8026010073E4B4 /* APCDataTracker.m in Sources */, F5F12A7A1A2F78490015982C /* APCAxisView.m in Sources */, 6CD8B6751AC5011D0061E6D6 /* APCTaskReminder.m in Sources */, F5B947EC1A73272C0034C522 /* APCDebugWindow.m in Sources */, diff --git a/APCAppCore/APCAppCore/Library/LocalJSONParser/APCLocalJSONParser.h b/APCAppCore/APCAppCore/Library/LocalJSONParser/APCLocalJSONParser.h new file mode 100644 index 00000000..47b9e80c --- /dev/null +++ b/APCAppCore/APCAppCore/Library/LocalJSONParser/APCLocalJSONParser.h @@ -0,0 +1,40 @@ +// +// APCLocalJSONParser.h +// APCAppCore +// +// Copyright (c) 2015, Apple Inc. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation and/or +// other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder(s) nor the names of any contributors +// may be used to endorse or promote products derived from this software without +// specific prior written permission. No license is granted to the trademarks of +// the copyright holders even if such marks are included in this software. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +#import + +@interface APCLocalJSONParser : NSObject + ++ (NSDictionary *)dictionaryFromJSONFileName:(NSString *)jsonFileName; + +@end diff --git a/APCAppCore/APCAppCore/Library/LocalJSONParser/APCLocalJSONParser.m b/APCAppCore/APCAppCore/Library/LocalJSONParser/APCLocalJSONParser.m new file mode 100644 index 00000000..363a415c --- /dev/null +++ b/APCAppCore/APCAppCore/Library/LocalJSONParser/APCLocalJSONParser.m @@ -0,0 +1,58 @@ +// +// APCLocalJSONParser.m +// APCAppCore +// +// Copyright (c) 2015, Apple Inc. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation and/or +// other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder(s) nor the names of any contributors +// may be used to endorse or promote products derived from this software without +// specific prior written permission. No license is granted to the trademarks of +// the copyright holders even if such marks are included in this software. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + + +#import "APCLocalJSONParser.h" +#import "APCLog.h" + +@implementation APCLocalJSONParser + ++ (NSDictionary *)dictionaryFromJSONFileName:(NSString *)jsonFileName +{ + NSString *filePath = [[NSBundle mainBundle] pathForResource:jsonFileName ofType:@"json"]; + NSAssert(filePath != nil, @"Unable to location file with Consent Section in main bundle"); + + NSString *JSONString = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL]; + + NSError *parseError = nil; + NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:[JSONString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&parseError]; + + if (jsonDictionary != nil) { + return jsonDictionary; + } else { + APCLogError2(parseError); + return nil; + } +} + +@end diff --git a/APCAppCore/APCAppCore/UI/TabBarControllers/Profile/APCProfile.storyboard b/APCAppCore/APCAppCore/UI/TabBarControllers/Profile/APCProfile.storyboard old mode 100644 new mode 100755 diff --git a/APCAppCore/APCAppCore/UI/TabBarControllers/Profile/APCSharingOptionsViewController.m b/APCAppCore/APCAppCore/UI/TabBarControllers/Profile/APCSharingOptionsViewController.m index 76174888..da7e8848 100644 --- a/APCAppCore/APCAppCore/UI/TabBarControllers/Profile/APCSharingOptionsViewController.m +++ b/APCAppCore/APCAppCore/UI/TabBarControllers/Profile/APCSharingOptionsViewController.m @@ -39,6 +39,7 @@ #import "APCUser+Bridge.h" #import "APCSpinnerViewController.h" #import "UIAlertController+Helper.h" +#import "APCLocalJSONParser.h" static NSString * const kSharingOptionsTableViewCellIdentifier = @"SharingOptionsTableViewCell"; static NSInteger kNumberOfRows = 2; @@ -99,14 +100,8 @@ - (void)prepareData - (void)setupDataFromJSON:(NSString *)jsonFileName { - NSString *filePath = [[NSBundle mainBundle] pathForResource:jsonFileName ofType:@"json"]; - NSString *JSONString = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL]; - - NSError *parseError; - NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:[JSONString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&parseError]; - - - if (!parseError) { + NSDictionary *jsonDictionary = [APCLocalJSONParser dictionaryFromJSONFileName:jsonFileName]; + if (jsonDictionary != nil) { NSDictionary *infoDictionary = jsonDictionary[@"documentProperties"]; self.instituteLongName = infoDictionary[@"investigatorLongDescription"]; self.instituteShortName = infoDictionary[@"investigatorShortDescription"]; @@ -193,4 +188,5 @@ - (IBAction)close:(id)__unused sender { [self dismissViewControllerAnimated:YES completion:nil]; } + @end diff --git a/APCAppCore/APCAppCore/UI/TabBarControllers/Profile/APCWithdrawSurveyViewController.m b/APCAppCore/APCAppCore/UI/TabBarControllers/Profile/APCWithdrawSurveyViewController.m index b3457a27..5e05332b 100644 --- a/APCAppCore/APCAppCore/UI/TabBarControllers/Profile/APCWithdrawSurveyViewController.m +++ b/APCAppCore/APCAppCore/UI/TabBarControllers/Profile/APCWithdrawSurveyViewController.m @@ -39,6 +39,7 @@ #import "UIImage+APCHelper.h" #import "APCAppCore.h" #import "APCUser+Bridge.h" +#import "APCLocalJSONParser.h" @interface APCWithdrawSurveyViewController () @@ -173,16 +174,11 @@ - (void) withdrawViewController: (APCWithdrawDescriptionViewController *) __unus - (NSArray *)surveyFromJSONFile:(NSString *)jsonFileName { - NSString *filePath = [[NSBundle mainBundle] pathForResource:jsonFileName ofType:@"json"]; - NSString *JSONString = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL]; - - NSError *parseError; - NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:[JSONString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&parseError]; + NSDictionary *jsonDictionary = [APCLocalJSONParser dictionaryFromJSONFileName:jsonFileName]; NSMutableArray *items = [NSMutableArray new]; - if (!parseError) { - + if (jsonDictionary != nil) { NSArray *options = jsonDictionary[@"options"]; NSMutableArray *rowItems = [NSMutableArray new];