diff options
Diffstat (limited to 'uiopen.mm')
-rw-r--r-- | uiopen.mm | 31 |
1 files changed, 23 insertions, 8 deletions
@@ -56,21 +56,36 @@ #include <stdio.h> #include <dlfcn.h> +@interface UIApplication (uiopen) +-(BOOL)launchApplicationWithIdentifier:(NSString*)identifier suspended:(BOOL)suspended; +@end + int main(int argc, char *argv[]) { if (argc != 2) { - fprintf(stderr, "usage: %s <url>\n", argv[0]); + fprintf(stderr, "usage: %s <url|bundleid>\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); } |