From 284520390d792703c0873b22d20b29e34a31cdcb Mon Sep 17 00:00:00 2001 From: Sam Bingner Date: Mon, 13 May 2024 11:48:00 -1000 Subject: Make uiopen support bundleid --- uiopen.mm | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'uiopen.mm') diff --git a/uiopen.mm b/uiopen.mm index 541c99f..f142740 100644 --- a/uiopen.mm +++ b/uiopen.mm @@ -56,21 +56,36 @@ #include #include +@interface UIApplication (uiopen) +-(BOOL)launchApplicationWithIdentifier:(NSString*)identifier suspended:(BOOL)suspended; +@end + int main(int argc, char *argv[]) { if (argc != 2) { - fprintf(stderr, "usage: %s \n", argv[0]); + fprintf(stderr, "usage: %s \n", argv[0]); return 1; } - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSString *arg = [NSString stringWithUTF8String:argv[1]]; + NSURL *url = [NSURL URLWithString:arg]; + UIApplication *app = [UIApplication alloc]; + + bool success = false; + // Try opening as a bundle ID + if (int (*SBSLaunchApplicationWithIdentifier)(CFStringRef id, BOOL suspended) = (int (*)(CFStringRef, BOOL)) dlsym(RTLD_DEFAULT, "SBSLaunchApplicationWithIdentifier")) + success = !(*SBSLaunchApplicationWithIdentifier)((__bridge CFStringRef)arg, false); + else + success = [app launchApplicationWithIdentifier:arg suspended:NO]; - NSURL *url([NSURL URLWithString:[NSString stringWithUTF8String:argv[1]]]); + if (success == YES) { + return 0; + } - if (void (*SBSOpenSensitiveURLAndUnlock)(NSURL *, BOOL) = (void (*)(NSURL *, BOOL)) dlsym(RTLD_DEFAULT, "SBSOpenSensitiveURLAndUnlock")) - (*SBSOpenSensitiveURLAndUnlock)(url, YES); + // Try opening as a URL + if (BOOL (*SBSOpenSensitiveURLAndUnlock)(NSURL *, BOOL) = (BOOL (*)(NSURL *, BOOL)) dlsym(RTLD_DEFAULT, "SBSOpenSensitiveURLAndUnlock")) + success = (*SBSOpenSensitiveURLAndUnlock)(url, YES); else - [[UIApplication alloc] openURL:url]; + success = [app openURL:url]; - [pool release]; - return 0; + return !(success == YES); } -- cgit v1.2.3