Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I couldn't find <code>NSRunningApplication</code> in the iOS (public or private) 5.0 headers (I'm pretty sure I checked everywhere, but I could be wrong ...)</p> <p>There's probably multiple ways to do this, but one of these should work ...</p> <p>First, get information about the running processes. If you can't get the bundle ID, but can get the <strong>path</strong> to the app, then that's good enough. You could do that in one of a few ways:</p> <p><strong>1)</strong> <a href="https://stackoverflow.com/questions/8275578/how-to-get-information-about-free-memory-and-running-processes-in-an-app-store-a">See this answer on stack overflow</a> or maybe <a href="https://stackoverflow.com/a/8278785/119114">this one</a>. I'm not sure the executable path is available with these techniques ... I didn't explore them in depth.</p> <p><strong>2)</strong> You <strong>can</strong> get process information through the <code>ps</code> shell command. For example, with a <code>ps -Aef</code> command at the command line:</p> <pre><code>iPhone4:~/Applications/8AA99EA8-9CFC-4C17-9BD1-7C2812EDAAD4/Starbucks.app mobile$ ps -Aef UID PID PPID C STIME TTY TIME CMD 501 281 1 0 0:00.00 ?? 1:02.39 /Applications/MobilePhone.app/MobilePhone 501 282 1 0 0:00.00 ?? 2:26.40 /Applications/MobileMail.app/MobileMail 501 479 1 0 0:00.00 ?? 5:45.01 /Applications/MobileSafari.app/MobileSafari 501 490 1 0 0:00.00 ?? 0:45.62 /Applications/Music~iphone.app/Music~iphone 501 912 1 0 0:00.00 ?? 0:17.65 /var/mobile/Applications/8AA99EA8-9CFC-4237-9BD1-7C2812AAAAD4/Starbucks.app/Starbucks 501 1933 1 0 0:00.00 ?? 0:51.72 /var/mobile/Applications/9962D9AE-087C-4D2E-A6AB-151230DBCDB09/Skype.app/Skype 501 2106 1 0 0:00.00 ?? 1:11.68 /var/mobile/Applications/20DCED79-B1EE-48F4-B3E1-75E9C25A0908C/Netflix.app/Netflix 501 2259 1 0 0:00.00 ?? 0:03.83 /Applications/Stocks.app/Stocks 501 2292 1 0 0:00.00 ?? 0:07.05 /var/mobile/Applications/33713030-9D3D-4BAC-8182-282973B2E5E0/ZillowMap.app/ZillowMap 501 2568 1 0 0:00.00 ?? 0:12.91 /var/mobile/Applications/55216130-10D8-498C-B477-AD18A4982E18/eBay.app/eBay 501 2587 1 0 0:00.00 ?? 0:05.10 /var/mobile/Applications/2A8DEAAD-8244-45C0-BEA9-20DA290B0117/Moviefone.app/Moviefone </code></pre> <p>I removed some of the output, but you can see some of the apps running (*.app). </p> <p>So, in your app, you could run <code>"ps -Aef &gt;&gt; /var/mobile/Library/MyAppName/ps.txt"</code> with a <code>system</code> or <code>exec</code> call, sending the output to a temporary file. Then, parse that file to get the results.</p> <p><strong>3)</strong> I also found a copy of the Darwin open source online, and hacked it up a little to collect this kind of data into a C string buffer, that can be parsed programmatically. Get the header and .c file here:</p> <p><a href="http://pastebin.com/EDWtGrhc" rel="nofollow noreferrer">darwin.c</a></p> <p><a href="http://pastebin.com/kiNEU669" rel="nofollow noreferrer">darwin.h</a></p> <p>Include those two files in your Xcode project, and <code>#include "darwin.h"</code>. Then, use it like so:</p> <pre><code>OS_initialize(); size_t buffSize = 20000; // you may need to increase this! char buffer[buffSize]; int bytes = OS_get_table(buffer, buffSize); if (bytes &gt; 0) { self.textView.text = [NSString stringWithCString: buffer encoding: NSASCIIStringEncoding]; } </code></pre> <p>Now that you have the apps' install locations, open up the Info.plists under those directories</p> <pre class="lang-objc prettyprint-override"><code>NSString* filename = @"/var/mobile/Applications/8AA99EA8-9CFC-4237-9BD1-7C2812EDAAD4/Starbucks.app/Info.plist"; NSDictionary* dict = [[NSDictionary alloc] initWithContentsOfFile: filename]; NSString* bundleID = [dict valueForKey: @"CFBundleIdentifier"]; </code></pre> <p>and read their bundle IDs.</p> <p>In order to make this work, you may need to gain root privileges for your app.</p> <p><a href="https://stackoverflow.com/a/8796556/119114">See here on how to do that</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload