Guest User

Untitled

a guest
May 19th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Enumerates applications in the Applications folder.
  2.  * Requires that you #include <stdio.h>.
  3.  */
  4.  
  5. //Get file descriptor to list of applications.
  6. FILE *list = popen("ls -d /var/mobile/Applications/*/*.app | cut -d '/' -f 6", "r");
  7. if (list == NULL) {
  8.   NSLog(@"Failed to invoke subprocess, dying...\n");
  9.   //die here.
  10. }
  11.  
  12. //read contents of list file
  13. NSMutableString *appList = [[NSMutableString alloc] init];
  14. char buf[32]; //buffer for appnames, doesn't really matter how long it is.
  15. while(fgets(str, 32, list) != NULL) { //more stuff to read
  16.   NSString NSbuf = [NSString stringWithCString: buf]; //convert it to objc form
  17.   [appList appendString: NSbuf]; //append it to list
  18. }
  19.  
  20. //convert contents into list
  21. NSArray *applications = [appList componentsSeparatedByString: @"\n"];
  22.  
  23. //clean up after ourselves
  24. pclose(list);
  25.  
  26. /* DISCLAIMER:
  27.  * That was just more C than I've done in a year or two,
  28.  * and more Objective-C than I've done *ever*.
  29.  *
  30.  * Get someone else to read it,
  31.  * and PLEASE don't hesitate to blame it for any interesting bugs.
  32.  */
Add Comment
Please, Sign In to add comment