Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Enumerates applications in the Applications folder.
- * Requires that you #include <stdio.h>.
- */
- //Get file descriptor to list of applications.
- FILE *list = popen("ls -d /var/mobile/Applications/*/*.app | cut -d '/' -f 6", "r");
- if (list == NULL) {
- NSLog(@"Failed to invoke subprocess, dying...\n");
- //die here.
- }
- //read contents of list file
- NSMutableString *appList = [[NSMutableString alloc] init];
- char buf[32]; //buffer for appnames, doesn't really matter how long it is.
- while(fgets(str, 32, list) != NULL) { //more stuff to read
- NSString NSbuf = [NSString stringWithCString: buf]; //convert it to objc form
- [appList appendString: NSbuf]; //append it to list
- }
- //convert contents into list
- NSArray *applications = [appList componentsSeparatedByString: @"\n"];
- //clean up after ourselves
- pclose(list);
- /* DISCLAIMER:
- * That was just more C than I've done in a year or two,
- * and more Objective-C than I've done *ever*.
- *
- * Get someone else to read it,
- * and PLEASE don't hesitate to blame it for any interesting bugs.
- */
Add Comment
Please, Sign In to add comment