From c5acbbafeb9dd2b728942677fe7ed5f852e5e6c8 Mon Sep 17 00:00:00 2001 From: Vineet Choudhary Date: Wed, 1 Feb 2017 17:21:47 +0530 Subject: [PATCH 1/4] Stored Xcode path in userdefault --- AppBox/Base.lproj/Main.storyboard | 4 ++-- AppBox/Common/UserData/UserData.h | 3 +++ AppBox/Common/UserData/UserData.m | 15 +++++++++++++++ AppBox/Info.plist | 2 +- .../ProjectAdvancedViewController.m | 18 +++++++++++++----- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/AppBox/Base.lproj/Main.storyboard b/AppBox/Base.lproj/Main.storyboard index 504dcc49..d281e4b5 100644 --- a/AppBox/Base.lproj/Main.storyboard +++ b/AppBox/Base.lproj/Main.storyboard @@ -1030,8 +1030,8 @@ Gw - - + + diff --git a/AppBox/Common/UserData/UserData.h b/AppBox/Common/UserData/UserData.h index b10ed8b5..4c9cee51 100644 --- a/AppBox/Common/UserData/UserData.h +++ b/AppBox/Common/UserData/UserData.h @@ -22,6 +22,9 @@ +(NSURL *)buildLocation; +(void)setBuildLocation:(NSURL *)buildLocation; ++(NSString *)xCodeLocation; ++(void)setXCodeLocation:(NSString *)xCodeLocation; + +(NSNumber *)dropboxUsedSpace; +(NSNumber *)dropboxAvailableSpace; +(void)setDropboxUsedSpace:(NSNumber *)usedSpace; diff --git a/AppBox/Common/UserData/UserData.m b/AppBox/Common/UserData/UserData.m index e661ed37..29a7f056 100644 --- a/AppBox/Common/UserData/UserData.m +++ b/AppBox/Common/UserData/UserData.m @@ -63,6 +63,21 @@ +(void)setBuildLocation:(NSURL *)buildLocation{ [[NSUserDefaults standardUserDefaults] synchronize]; } +#define XCodeLocation @"XCodeLocation" + ++(NSString *)xCodeLocation{ + NSString *xCodeLocation = [[NSUserDefaults standardUserDefaults] stringForKey:XCodeLocation]; + if (xCodeLocation == nil){ + xCodeLocation = abXcodeLocation; + } + return xCodeLocation; +} + ++(void)setXCodeLocation:(NSString *)xCodeLocation{ + [[NSUserDefaults standardUserDefaults] setValue:xCodeLocation forKey:XCodeLocation]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + #pragma mark - Dropbox #define DropboxUsedSpace @"DropboxUsedSpace" #define DropboxAvailableSpace @"DropboxAvailableSpace" diff --git a/AppBox/Info.plist b/AppBox/Info.plist index 3fcd168a..131b6ba8 100644 --- a/AppBox/Info.plist +++ b/AppBox/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.1.0 + 1.1.1 CFBundleSignature ???? CFBundleURLTypes diff --git a/AppBox/ViewController/ProjectAdvancedViewController/ProjectAdvancedViewController.m b/AppBox/ViewController/ProjectAdvancedViewController/ProjectAdvancedViewController.m index 73dd1860..bae69022 100644 --- a/AppBox/ViewController/ProjectAdvancedViewController/ProjectAdvancedViewController.m +++ b/AppBox/ViewController/ProjectAdvancedViewController/ProjectAdvancedViewController.m @@ -16,8 +16,9 @@ - (void)viewDidLoad { [super viewDidLoad]; [Common logScreen:@"Project Advanced Settings"]; if ([self.project.buildType isEqualToString:BuildTypeAppStore]){ - if ([[NSFileManager defaultManager] fileExistsAtPath:abXcodeLocation]){ - [pathXCode setURL: [NSURL URLWithString:abXcodeLocation]]; + NSString *xcodePath = [UserData xCodeLocation]; + if ([[NSFileManager defaultManager] fileExistsAtPath:xcodePath]){ + [pathXCode setURL: [NSURL URLWithString:xcodePath]]; } }else{ [pathXCode setEnabled:NO]; @@ -33,6 +34,7 @@ - (void)viewDidLoad { } } +//MARK: - Action Button Tapped - (IBAction)buttonCancelTapped:(NSButton *)sender { [self dismissController:self]; } @@ -41,14 +43,19 @@ - (IBAction)buttonSaveTapped:(NSButton *)sender { [[textFieldPassword window] makeFirstResponder:self.view]; [UserData setBuildLocation:self.project.buildDirectory]; - //set username and password - [self.project setItcUserName:textFieldUserName.stringValue]; + //set xcode and application loader path if (pathXCode.URL.isFileURL){ [self.project setXcodePath:[pathXCode.URL.filePathURL resourceSpecifier]]; }else{ [self.project setXcodePath: pathXCode.URL.absoluteString]; } [self.project setAlPath: [[self.project.xcodePath stringByAppendingPathComponent:abApplicationLoaderLocation] stringByRemovingPercentEncoding]]; + + //set xcode location + [UserData setXCodeLocation:self.project.xcodePath]; + + //set username and password + [self.project setItcUserName:textFieldUserName.stringValue]; if (textFieldPassword.stringValue.length > 0){ [self.project setItcPasswod:textFieldPassword.stringValue]; //save username and password in keychain @@ -69,7 +76,8 @@ - (IBAction)buildPathHandler:(NSPathControl *)sender { } } +//Xcode Path Handler - (IBAction)xcodePathHandler:(NSPathControl *)sender { - + } @end From b9d352ac46ee74f8bcdd46a7a3ef29aab1057c95 Mon Sep 17 00:00:00 2001 From: Vineet Choudhary Date: Sat, 4 Feb 2017 15:29:27 +0530 Subject: [PATCH 2/4] handle ipa/manifest share link failed request either ongoing or start --- AppBox/AppDelegate.m | 8 - .../HomeViewController/HomeViewController.m | 175 +++++++++++------- 2 files changed, 110 insertions(+), 73 deletions(-) diff --git a/AppBox/AppDelegate.m b/AppBox/AppDelegate.m index 9639c310..94fdb35a 100644 --- a/AppBox/AppDelegate.m +++ b/AppBox/AppDelegate.m @@ -29,14 +29,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [[NSUserDefaults standardUserDefaults] registerDefaults:@{ @"NSApplicationCrashOnExceptions": @YES }]; [Fabric with:@[[Crashlytics class], [Answers class]]]; - //Start monitoring internet connection - [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { - if (status == AFNetworkReachabilityStatusNotReachable){ - [Common showAlertWithTitle:@"Error" andMessage:AFStringFromNetworkReachabilityStatus(status)]; - } - }]; - [[AFNetworkReachabilityManager sharedManager] startMonitoring]; - //Handle URL Scheme [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleGetURLWithEvent:andReply:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; diff --git a/AppBox/ViewController/HomeViewController/HomeViewController.m b/AppBox/ViewController/HomeViewController/HomeViewController.m index 806968fb..af7aef73 100644 --- a/AppBox/ViewController/HomeViewController/HomeViewController.m +++ b/AppBox/ViewController/HomeViewController/HomeViewController.m @@ -17,6 +17,7 @@ @implementation HomeViewController{ ScriptType scriptType; FileType fileType; NSArray *allTeamIds; + NSBlockOperation *lastfailedOperation; } - (void)viewDidLoad { @@ -38,6 +39,22 @@ - (void)viewDidLoad { //update available memory [[NSApplication sharedApplication] updateDropboxUsage]; + + //Start monitoring internet connection + [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { + if ([AppDelegate appDelegate].processing){ + if (status == AFNetworkReachabilityStatusNotReachable){ + [self showStatus:@"Waiting for the Internet Connection." andShowProgressBar:YES withProgress:-1]; + }else{ + [self showStatus:@"Connected to the Internet." andShowProgressBar:NO withProgress:-1]; + //restart last failed operation + if (lastfailedOperation){ + [lastfailedOperation start]; + } + } + } + }]; + [[AFNetworkReachabilityManager sharedManager] startMonitoring]; } - (void)viewWillAppear{ @@ -516,7 +533,7 @@ -(void)dbUploadFile:(NSURL *)file to:(NSString *)path mode:(DBFILESWriteMode *)m return; }else{ //create shared url for appinfo.json - [self dbSharedURLForFile:result.pathDisplay]; + [self dbCreateSharedURLForFile:result.pathDisplay]; } } //IPA file uploaded and creating shared url @@ -526,7 +543,7 @@ -(void)dbUploadFile:(NSURL *)file to:(NSString *)path mode:(DBFILESWriteMode *)m [self showStatus:status andShowProgressBar:YES withProgress:-1]; //create shared url for ipa - [self dbSharedURLForFile:result.pathDisplay]; + [self dbCreateSharedURLForFile:result.pathDisplay]; } //Manifest file uploaded and creating shared url else if (fileType == FileTypeManifest){ @@ -535,13 +552,13 @@ -(void)dbUploadFile:(NSURL *)file to:(NSString *)path mode:(DBFILESWriteMode *)m [self showStatus:status andShowProgressBar:YES withProgress:-1]; //create shared url for manifest - [self dbSharedURLForFile:result.pathDisplay]; + [self dbCreateSharedURLForFile:result.pathDisplay]; } } //unable to upload file, show error else { NSLog(@"%@\n%@\n", routeError, error); - [Common showAlertWithTitle:@"Error" andMessage:error.errorContent]; + [Common showAlertWithTitle:@"Error" andMessage:error.nsError.localizedDescription]; [self viewStateForProgressFinish:YES]; } }] @@ -563,75 +580,100 @@ -(void)dbUploadFile:(NSURL *)file to:(NSString *)path mode:(DBFILESWriteMode *)m }]; } --(void)dbSharedURLForFile:(NSString *)file{ +-(void)dbCreateSharedURLForFile:(NSString *)file{ [[[DropboxClientsManager authorizedClient].sharingRoutes createSharedLinkWithSettings:file] //Track response with result and error response:^(DBSHARINGSharedLinkMetadata * _Nullable result, DBSHARINGCreateSharedLinkWithSettingsError * _Nullable settingError, DBRequestError * _Nullable error) { if (result){ - - //Create manifest file with share IPA url and upload manifest file - if (fileType == FileTypeIPA) { - NSString *shareableLink = [result.url stringByReplacingCharactersInRange:NSMakeRange(result.url.length-1, 1) withString:@"1"]; - project.ipaFileDBShareableURL = [NSURL URLWithString:shareableLink]; - [project createManifestWithIPAURL:project.ipaFileDBShareableURL completion:^(NSURL *manifestURL) { - if (manifestURL == nil){ - //show error if manifest file url is nil - [Common showAlertWithTitle:@"Error" andMessage:@"Unable to create manifest file!!"]; - [self viewStateForProgressFinish:YES]; - }else{ - //change file type and upload manifest - fileType = FileTypeManifest; - [self dbUploadFile:manifestURL to:project.dbManifestFullPath.absoluteString mode:[[DBFILESWriteMode alloc] initWithOverwrite]]; - } - }]; - - } - //if same link enable load appinfo.json otherwise Create short shareable url of manifest - else if (fileType == FileTypeManifest){ - NSString *shareableLink = [result.url substringToIndex:result.url.length-5]; - [[AppDelegate appDelegate] addSessionLog:[NSString stringWithFormat:@"Manifest Sharable link - %@",shareableLink]]; - project.manifestFileSharableURL = [NSURL URLWithString:shareableLink]; - if(buttonUniqueLink.state){ - //Download previously uploaded appinfo - [[[DropboxClientsManager authorizedClient].filesRoutes listRevisions:project.dbAppInfoJSONFullPath.absoluteString limit:@1] - response:^(DBFILESListRevisionsResult * _Nullable result, DBFILESListRevisionsError * _Nullable revError, DBRequestError * _Nullable error) { - - //check there is any rev available - if (result && result.isDeleted.boolValue == NO && result.entries.count > 0){ - [[AppDelegate appDelegate] addSessionLog:[NSString stringWithFormat:@"Loaded Meta Data %@",result]]; - project.uniqueLinkJsonMetaData = [result.entries firstObject]; - } - - //handle meta data - [self handleAfterUniqueJsonMetaDataLoaded]; - }]; - }else{ - [self createManifestShortSharableUrl]; - } - } - - //create app info file short sharable url - else if (fileType == FileTypeJson){ - NSString *shareableLink = [result.url substringToIndex:result.url.length-5]; - [[AppDelegate appDelegate] addSessionLog:[NSString stringWithFormat:@"APPInfo Sharable link - %@",shareableLink]]; - project.uniquelinkShareableURL = [NSURL URLWithString:shareableLink]; - NSMutableDictionary *dictUniqueFile = [[self getUniqueJsonDict] mutableCopy]; - [dictUniqueFile setObject:shareableLink forKey:UNIQUE_LINK_SHARED]; - [self writeUniqueJsonWithDict:dictUniqueFile]; - if(project.appShortShareableURL){ - [self showURL]; - }else{ - [self createUniqueShortSharableUrl]; - } - - } + [self handleSharedURLResult:result.url]; }else{ - [Common showAlertWithTitle:@"Error" andMessage:error.errorContent]; - [self viewStateForProgressFinish:YES]; + [self handleSharedURLError:error forFile:file]; } }]; } +-(void)dbGetSharedURLForFile:(NSString *)file{ + [[[DropboxClientsManager authorizedClient].sharingRoutes listSharedLinks:file cursor:nil directOnly:nil] response:^(DBSHARINGListSharedLinksResult * _Nullable results, DBSHARINGListSharedLinksError * _Nullable linksError, DBRequestError * _Nullable error) { + if (results && results.links.count > 0){ + [self handleSharedURLResult:[[results.links firstObject] url]]; + }else{ + [self handleSharedURLError:error forFile:file]; + } + }]; +} + +-(void)handleSharedURLError:(DBRequestError *)error forFile:(NSString *)file{ + NSLog(@"%@\n", error); + if ([error isClientError]){ + lastfailedOperation = [NSBlockOperation blockOperationWithBlock:^{ + [self dbCreateSharedURLForFile:file]; + }]; + }else if([error isHttpError] && error.statusCode.integerValue == 409){ + [self dbGetSharedURLForFile:file]; + }else{ + [Common showAlertWithTitle:@"Error" andMessage:error.nsError.localizedDescription]; + [self viewStateForProgressFinish:YES]; + } +} + +-(void)handleSharedURLResult:(NSString *)url{ + //Create manifest file with share IPA url and upload manifest file + if (fileType == FileTypeIPA) { + NSString *shareableLink = [url stringByReplacingCharactersInRange:NSMakeRange(url.length-1, 1) withString:@"1"]; + project.ipaFileDBShareableURL = [NSURL URLWithString:shareableLink]; + [project createManifestWithIPAURL:project.ipaFileDBShareableURL completion:^(NSURL *manifestURL) { + if (manifestURL == nil){ + //show error if manifest file url is nil + [Common showAlertWithTitle:@"Error" andMessage:@"Unable to create manifest file!!"]; + [self viewStateForProgressFinish:YES]; + }else{ + //change file type and upload manifest + fileType = FileTypeManifest; + [self dbUploadFile:manifestURL to:project.dbManifestFullPath.absoluteString mode:[[DBFILESWriteMode alloc] initWithOverwrite]]; + } + }]; + + } + //if same link enable load appinfo.json otherwise Create short shareable url of manifest + else if (fileType == FileTypeManifest){ + NSString *shareableLink = [url substringToIndex:url.length-5]; + [[AppDelegate appDelegate] addSessionLog:[NSString stringWithFormat:@"Manifest Sharable link - %@",shareableLink]]; + project.manifestFileSharableURL = [NSURL URLWithString:shareableLink]; + if(buttonUniqueLink.state){ + //Download previously uploaded appinfo + [[[DropboxClientsManager authorizedClient].filesRoutes listRevisions:project.dbAppInfoJSONFullPath.absoluteString limit:@1] + response:^(DBFILESListRevisionsResult * _Nullable result, DBFILESListRevisionsError * _Nullable revError, DBRequestError * _Nullable error) { + + //check there is any rev available + if (result && result.isDeleted.boolValue == NO && result.entries.count > 0){ + [[AppDelegate appDelegate] addSessionLog:[NSString stringWithFormat:@"Loaded Meta Data %@",result]]; + project.uniqueLinkJsonMetaData = [result.entries firstObject]; + } + + //handle meta data + [self handleAfterUniqueJsonMetaDataLoaded]; + }]; + }else{ + [self createManifestShortSharableUrl]; + } + } + + //create app info file short sharable url + else if (fileType == FileTypeJson){ + NSString *shareableLink = [url substringToIndex:url.length-5]; + [[AppDelegate appDelegate] addSessionLog:[NSString stringWithFormat:@"APPInfo Sharable link - %@",shareableLink]]; + project.uniquelinkShareableURL = [NSURL URLWithString:shareableLink]; + NSMutableDictionary *dictUniqueFile = [[self getUniqueJsonDict] mutableCopy]; + [dictUniqueFile setObject:shareableLink forKey:UNIQUE_LINK_SHARED]; + [self writeUniqueJsonWithDict:dictUniqueFile]; + if(project.appShortShareableURL){ + [self showURL]; + }else{ + [self createUniqueShortSharableUrl]; + } + } +} + #pragma mark - Updating Unique Link - -(void)updateUniquLinkDictinory:(NSMutableDictionary *)dictUniqueLink{ if(![dictUniqueLink isKindOfClass:[NSDictionary class]]) @@ -696,7 +738,7 @@ -(void)handleAfterUniqueJsonMetaDataLoaded{ } } else if (downloadError || error){ - [[AppDelegate appDelegate] addSessionLog:[NSString stringWithFormat:@"Error while loading metadata %@",error]]; + [[AppDelegate appDelegate] addSessionLog:[NSString stringWithFormat:@"Error while loading metadata %@",error.nsError.localizedDescription]]; //create new appinfo.json [self handleAfterUniqueJsonMetaDataLoaded]; } @@ -868,6 +910,9 @@ -(void)updateViewState{ [buttonAction setEnabled:(enable && (pathProject.enabled || pathIPAFile.enabled))]; [buttonAction setTitle:(tabView.selectedTabViewItem.label)]; + //update keepsame link + [buttonUniqueLink setEnabled:(project.buildType == nil || ![project.buildType isEqualToString:BuildTypeAppStore])]; + //update advanced button [buttonAdcanced setEnabled:buttonAction.enabled]; From 96501bddb37070702595ac4a71dd48973c0ffb46 Mon Sep 17 00:00:00 2001 From: Vineet Choudhary Date: Sat, 4 Feb 2017 16:13:13 +0530 Subject: [PATCH 3/4] Rearrange code and handle shared links urls --- .../HomeViewController/HomeViewController.m | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/AppBox/ViewController/HomeViewController/HomeViewController.m b/AppBox/ViewController/HomeViewController/HomeViewController.m index af7aef73..11014c95 100644 --- a/AppBox/ViewController/HomeViewController/HomeViewController.m +++ b/AppBox/ViewController/HomeViewController/HomeViewController.m @@ -50,6 +50,7 @@ - (void)viewDidLoad { //restart last failed operation if (lastfailedOperation){ [lastfailedOperation start]; + lastfailedOperation = nil; } } } @@ -517,6 +518,23 @@ -(void)uploadIPAFileWithLocalURL:(NSURL *)ipaURL{ [[AppDelegate appDelegate] addSessionLog:[NSString stringWithFormat:@"Temporaray folder %@",NSTemporaryDirectory()]]; } +#pragma mark - Dropbox Helper - +#pragma mark → Dropbox Notification Handler +- (void)handleLoggedInNotification:(NSNotification *)notification{ + [self updateMenuButtons]; + [self viewStateForProgressFinish:YES]; +} + +- (void)dropboxLogoutHandler:(id)sender{ + //handle dropbox logout for authorized users + if ([DropboxClientsManager authorizedClient]){ + [DropboxClientsManager unlinkClients]; + [self viewStateForProgressFinish:YES]; + [self performSegueWithIdentifier:@"DropBoxLogin" sender:self]; + } +} + +#pragma mark → Dropbox Upload Files -(void)dbUploadFile:(NSURL *)file to:(NSString *)path mode:(DBFILESWriteMode *)mode{ //uploadUrl:path inputUrl:file [[[[DropboxClientsManager authorizedClient].filesRoutes uploadUrl:path mode:mode autorename:@NO clientModified:nil mute:@NO inputUrl:file] @@ -580,6 +598,8 @@ -(void)dbUploadFile:(NSURL *)file to:(NSString *)path mode:(DBFILESWriteMode *)m }]; } + +#pragma mark → Dropbox Create/Get Shared Link -(void)dbCreateSharedURLForFile:(NSString *)file{ [[[DropboxClientsManager authorizedClient].sharingRoutes createSharedLinkWithSettings:file] //Track response with result and error @@ -594,7 +614,7 @@ -(void)dbCreateSharedURLForFile:(NSString *)file{ -(void)dbGetSharedURLForFile:(NSString *)file{ [[[DropboxClientsManager authorizedClient].sharingRoutes listSharedLinks:file cursor:nil directOnly:nil] response:^(DBSHARINGListSharedLinksResult * _Nullable results, DBSHARINGListSharedLinksError * _Nullable linksError, DBRequestError * _Nullable error) { - if (results && results.links.count > 0){ + if (results && results.links && results.links.count > 0){ [self handleSharedURLResult:[[results.links firstObject] url]]; }else{ [self handleSharedURLError:error forFile:file]; @@ -748,22 +768,6 @@ -(void)handleAfterUniqueJsonMetaDataLoaded{ } } - -#pragma mark → Dropbox Helper -- (void)handleLoggedInNotification:(NSNotification *)notification{ - [self updateMenuButtons]; - [self viewStateForProgressFinish:YES]; -} - -- (void)dropboxLogoutHandler:(id)sender{ - //handle dropbox logout for authorized users - if ([DropboxClientsManager authorizedClient]){ - [DropboxClientsManager unlinkClients]; - [self viewStateForProgressFinish:YES]; - [self performSegueWithIdentifier:@"DropBoxLogin" sender:self]; - } -} - #pragma mark - Create ShortSharable URL - -(void)createUniqueShortSharableUrl{ NSString *originalURL = [project.uniquelinkShareableURL.absoluteString componentsSeparatedByString:@"dropbox.com"][1]; From b6ab8dadf4c0bf4c5a845475fa3881c6374199a8 Mon Sep 17 00:00:00 2001 From: Vineet Choudhary Date: Sat, 4 Feb 2017 16:43:30 +0530 Subject: [PATCH 4/4] disabled unique links button only for appstore builds --- AppBox/ViewController/HomeViewController/HomeViewController.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AppBox/ViewController/HomeViewController/HomeViewController.m b/AppBox/ViewController/HomeViewController/HomeViewController.m index 11014c95..e03e3890 100644 --- a/AppBox/ViewController/HomeViewController/HomeViewController.m +++ b/AppBox/ViewController/HomeViewController/HomeViewController.m @@ -915,7 +915,8 @@ -(void)updateViewState{ [buttonAction setTitle:(tabView.selectedTabViewItem.label)]; //update keepsame link - [buttonUniqueLink setEnabled:(project.buildType == nil || ![project.buildType isEqualToString:BuildTypeAppStore])]; + [buttonUniqueLink setEnabled:(project.buildType == nil || ![project.buildType isEqualToString:BuildTypeAppStore] || + tabView.tabViewItems.lastObject.tabState == NSSelectedTab)]; //update advanced button [buttonAdcanced setEnabled:buttonAction.enabled];