Skip to content

Commit

Permalink
Merge pull request #54 from vineetchoudhary/development
Browse files Browse the repository at this point in the history
Handle ipa/manifest share link failed request either ongoing or start
  • Loading branch information
vineetchoudhary authored Feb 4, 2017
2 parents a266691 + ca912f2 commit 746d612
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 97 deletions.
8 changes: 0 additions & 8 deletions AppBox/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
4 changes: 2 additions & 2 deletions AppBox/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,8 @@ Gw
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="0fz-Iv-tzW">
<rect key="frame" x="13" y="161" width="151" height="21"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="AppStore Settings" placeholderString="" id="IXK-Ft-xCe">
<rect key="frame" x="13" y="161" width="204" height="21"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="AppStore Settings (Beta)" placeholderString="" id="IXK-Ft-xCe">
<font key="font" metaFont="systemSemibold" size="17"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
Expand Down
3 changes: 3 additions & 0 deletions AppBox/Common/UserData/UserData.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
+(NSURL *)buildLocation;
+(void)setBuildLocation:(NSURL *)buildLocation;

+(NSString *)xCodeLocation;
+(void)setXCodeLocation:(NSString *)xCodeLocation;

+(NSNumber *)dropboxUsedSpace;
+(NSNumber *)dropboxAvailableSpace;
+(void)setDropboxUsedSpace:(NSNumber *)usedSpace;
Expand Down
15 changes: 15 additions & 0 deletions AppBox/Common/UserData/UserData.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion AppBox/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1.0</string>
<string>1.1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down
212 changes: 131 additions & 81 deletions AppBox/ViewController/HomeViewController/HomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ @implementation HomeViewController{
ScriptType scriptType;
FileType fileType;
NSArray *allTeamIds;
NSBlockOperation *lastfailedOperation;
}

- (void)viewDidLoad {
Expand All @@ -38,6 +39,23 @@ - (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];
lastfailedOperation = nil;
}
}
}
}];
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
}

- (void)viewWillAppear{
Expand Down Expand Up @@ -500,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]
Expand All @@ -516,7 +551,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
Expand All @@ -526,7 +561,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){
Expand All @@ -535,13 +570,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];
}
}]
Expand All @@ -563,75 +598,102 @@ -(void)dbUploadFile:(NSURL *)file to:(NSString *)path mode:(DBFILESWriteMode *)m
}];
}

-(void)dbSharedURLForFile:(NSString *)file{

#pragma mark → Dropbox Create/Get Shared Link
-(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 && 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]])
Expand Down Expand Up @@ -696,7 +758,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];
}
Expand All @@ -706,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];
Expand Down Expand Up @@ -868,6 +914,10 @@ -(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] ||
tabView.tabViewItems.lastObject.tabState == NSSelectedTab)];

//update advanced button
[buttonAdcanced setEnabled:buttonAction.enabled];

Expand Down
Loading

0 comments on commit 746d612

Please sign in to comment.