From 736a467588513460327623bc7e07a22d63539cb6 Mon Sep 17 00:00:00 2001 From: osama alhour Date: Mon, 12 Sep 2022 17:10:50 +0300 Subject: [PATCH 1/2] Option to open apps in action sheet --- Helper/CoreServices.h | 1 + Store/TSAppTableViewController.m | 28 ++++++++++++++++++++++++++++ Store/TSApplicationsManager.h | 1 + Store/TSApplicationsManager.m | 5 +++++ 4 files changed, 35 insertions(+) diff --git a/Helper/CoreServices.h b/Helper/CoreServices.h index a2bb4fe..e80af10 100644 --- a/Helper/CoreServices.h +++ b/Helper/CoreServices.h @@ -23,6 +23,7 @@ - (BOOL)unregisterApplication:(id)arg1; - (BOOL)_LSPrivateRebuildApplicationDatabasesForSystemApps:(BOOL)arg1 internal:(BOOL)arg2 user:(BOOL)arg3; - (BOOL)uninstallApplication:(NSString*)arg1 withOptions:(id)arg2; +- (BOOL)openApplicationWithBundleID:(NSString *)arg1 ; - (void)enumerateApplicationsOfType:(NSUInteger)type block:(void (^)(LSApplicationProxy*))block; @end diff --git a/Store/TSAppTableViewController.m b/Store/TSAppTableViewController.m index ba96855..1e3e98b 100644 --- a/Store/TSAppTableViewController.m +++ b/Store/TSAppTableViewController.m @@ -39,6 +39,27 @@ [self presentViewController:errorAlert animated:YES completion:nil]; } +- (void)openAppPressedForRowAtIndexPath:(NSIndexPath *)indexPath +{ + TSApplicationsManager* appsManager = [TSApplicationsManager sharedInstance]; + + NSString* appPath = [appsManager installedAppPaths][indexPath.row]; + NSString* appId = [appsManager appIdForAppPath:appPath]; + BOOL didOpen = [appsManager openApplicationWithBundleID:appId]; + + // if we failed to open the app, show an alert + if (!didOpen) { + NSString *failMessage = [NSString stringWithFormat: @"Failed to open %@", appId]; + UIAlertController* didFailController = [UIAlertController alertControllerWithTitle:failMessage message: nil preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction* action) + { + }]; + + [didFailController addAction: cancelAction]; + [self presentViewController:didFailController animated:YES completion:nil]; + } +} + - (void)uninstallPressedForRowAtIndexPath:(NSIndexPath*)indexPath { TSApplicationsManager* appsManager = [TSApplicationsManager sharedInstance]; @@ -134,6 +155,13 @@ }]; [appSelectAlert addAction:detachAction];*/ + + UIAlertAction* openAction = [UIAlertAction actionWithTitle: @"Open" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action) + { + [self openAppPressedForRowAtIndexPath:indexPath]; + }]; + [appSelectAlert addAction: openAction]; + UIAlertAction* uninstallAction = [UIAlertAction actionWithTitle:@"Uninstall App" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action) { [self uninstallPressedForRowAtIndexPath:indexPath]; diff --git a/Store/TSApplicationsManager.h b/Store/TSApplicationsManager.h index 8b84227..c3c9723 100644 --- a/Store/TSApplicationsManager.h +++ b/Store/TSApplicationsManager.h @@ -19,6 +19,7 @@ - (int)installIpa:(NSString*)pathToIpa; - (int)uninstallApp:(NSString*)appId; - (int)uninstallAppByPath:(NSString*)path; +- (BOOL)openApplicationWithBundleID:(NSString *)appID; //- (int)detachFromApp:(NSString*)appId; @end \ No newline at end of file diff --git a/Store/TSApplicationsManager.m b/Store/TSApplicationsManager.m index 2ae492f..5a70a13 100644 --- a/Store/TSApplicationsManager.m +++ b/Store/TSApplicationsManager.m @@ -148,6 +148,11 @@ return ret; } +- (BOOL)openApplicationWithBundleID:(NSString *)appId +{ + return [[LSApplicationWorkspace defaultWorkspace] openApplicationWithBundleID:appId]; +} + /*- (int)detachFromApp:(NSString*)appId { if(!appId) return -200; From f1f4060dca0ece1b5036ab76d3c5864139e7cac8 Mon Sep 17 00:00:00 2001 From: osama alhour Date: Mon, 12 Sep 2022 17:16:49 +0300 Subject: [PATCH 2/2] make code more readable by nullifying handler --- Store/TSAppTableViewController.m | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Store/TSAppTableViewController.m b/Store/TSAppTableViewController.m index 1e3e98b..c82713d 100644 --- a/Store/TSAppTableViewController.m +++ b/Store/TSAppTableViewController.m @@ -51,9 +51,7 @@ if (!didOpen) { NSString *failMessage = [NSString stringWithFormat: @"Failed to open %@", appId]; UIAlertController* didFailController = [UIAlertController alertControllerWithTitle:failMessage message: nil preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction* action) - { - }]; + UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; [didFailController addAction: cancelAction]; [self presentViewController:didFailController animated:YES completion:nil];