Dev:Compiling iOS applications on-device

This article will be useful to anyone that does not have or want to buy a Mac to compile apps or does not want to pay the $100/year fee to run code on your own device.

You don't even need a secondary desktop or a laptop to do this! However it is not recommended to physically code the app directly on-device using the virtual keyboard and iFile/MobileTerminal, unless if you're a masochist or something.

= Prerequisites =

Acquire an iOS device with iOS 5 or higher and jailbreak it.

This technically could work with lower iOS versions, but the available toolchain on Cydia was compiled for iOS 5.

= Creating an "app" on the homescreen =

In order to draw you in, we'll start with the easy bit first. This will just put an icon on your homescreen. No coding required for this section.

Run these commands (as root, default password alpine):

Then create a file Info.plist in /Applications/Test.app/ with the following contents:

Then login as mobile (default password alpine) and run:

If you did everything right, once the command is done running you should see this on your homescreen:

(On iOS 6 and lower, there would be no lines in the white square)

When you try to open the app, it will crash!

That's because your app doesn't have any actual code in it, it's just an empty file so it automatically exits. That's where installing the toolchain comes in, so we can actually write and compile code that runs on iOS.

= Install the toolchain =

Open Cydia and install these:


 * Tape archive
 * iOS toolchain
 * OpenSSH
 * wget

Or just run  as root (default password: alpine</tt>). Make sure to change the root and mobile passwords after installing OpenSSH.

= Get the SDK =

The legitimate way to get the SDK is by downloading XCode on a Mac or Windows computer and grabbing the SDK yourself - see Retrieving SDKs. If that's not an option for you, they are found here: http://iphone.howett.net/sdks/

You can use any SDK you want (like iOS 2) as long as they have the frameworks you need, however it is recommended you use the iOS 7 SDK or higher as the lower ones do not support arm64 (optimized for iPhone 5s and higher).

Right click "Download" on one of the SDKs and copy the link.

SSH into your device (user: root</tt> or mobile</tt>, default password: alpine</tt> for both) and run these commands:

Boom. Your device can now compile iOS applications!

= Finally, writing an actual working app =

This will not be the best written app in the world, but it will have enough explanation for you to understand what you need to do if you want multiple files.

Make a folder in /var/mobile</tt> called code</tt> (or something), just somewhere to hold your code.

Change directory into this folder and make 3 files: main.m</tt>, TestLabel.h</tt>, and TestLabel.m</tt>.

TestLabel.m</tt>
= Compiling the code =

Run these commands:

= Installing the app you compiled =

If you didn't get any errors, when you list the contents of the directory with your code in it you should see this:

Copy Test</tt> into /Applications/Test.app/ and overwrite the old empty Test</tt> file you created earlier.

Then, go ahead and open the app again and you should see this:



WAU, that AMAZING!!!1!

= Other details =

Using other frameworks
For example, if you wanted to use AVFoundation, add the -framework AVFoundation</tt> flag during the last compile step (similar to how I used -framework UIKit</tt> and -framework Foundation</tt>).

Removing the black letterboxing on 4-inch devices
To get the app to use the entire screen real-estate you need to add a the file Default-568h@2x.png</tt> to <tt>/Applications/Test.app/</tt>. The file needs to be 640x1136 pixels. Instead of creating it yourself, you could just copy it in from another application (like <tt>/Applications/Cydia/Default-568h@2x.png</tt>).

You will also need to run <tt>uicache</tt> again as <tt>mobile</tt> in order to see these changes take effect.

Enabling automatic reference counting (ARC)
Add the <tt>-fobjc-arc</tt> flag when compiling.

Icons, default backgrounds, entitlements, iPad compatibility, etc
Check out Apple's documentation on the subject. You can also look in any of the other <tt>Info.plist</tt>s in the <tt>/Applications/</tt> directory on your device! <tt>Cydia.app</tt> would be a good place to start.

Every change to <tt>Info.plist</tt> or the application's icons must be followed by the command <tt>uicache</tt> as <tt>mobile</tt> in order to see changes take effect.

Uninstalling
Delete it from <tt>/Applications/</tt> and run <tt>uicache</tt> as <tt>mobile</tt> again. iOS thinks it's a system app, so you can't delete it like a normal iOS app.

Getting it on the App Store
lol