m (→TestLabel.m.m) |
|||
Line 159: | Line 159: | ||
<source lang="bash"> | <source lang="bash"> | ||
clang -isysroot | clang -isysroot /var/mobile/sdks/latest \ | ||
-c main.m | -c main.m | ||
clang -isysroot | clang -isysroot /var/mobile/sdks/latest \ | ||
-c TestLabel.m | -c TestLabel.m | ||
clang -isysroot | clang -isysroot /var/mobile/sdks/latest \ | ||
-framework Foundation \ | -framework Foundation \ | ||
-framework UIKit \ | -framework UIKit \ |
Revision as of 00:02, 3 December 2014
Prerequisites
Aquire an iOS device with iOS 5 or higher and jailbreak it.
Install the toolchain
Open Cydia and install these:
- Tape archive
- iOS toolchain
- OpenSSH
- wget
Or just run apt-get install tar org.coolstar.iostoolchain openssh wget as root.
Get the SDK
They are found here: http://iphone.howett.net/sdks/
You can literally use any SDK you want 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 and run these commands:
cd /var/mobile
mkdir sdks
cd sdks
wget http://iphone.howett.net/sdks/dl/iPhoneOS8.1.sdk.tbz2 #or whatever SDK you wanted
tar xvf iPhoneOS8.1.sdk.tbz2
rm iPhoneOS8.1.sdk.tbz2
ln -s iPhoneOS8.1.sdk latest
Boom. Your device can fully now compile iOS applications.
Creating a vanilla app
Creating the app structure
Switch to root (if you already aren't) and run these commands:
cd /Applications
mkdir Test.app
cd Test.app
touch Test
chmod +x Test
Then create a file Info.plist in /Applications/Test.app/ with the following contents:
<dict>
<key>CFBundleExecutable</key>
<string>Test</string>
<key>CFBundleIdentifier</key>
<string>net.iphonedevwiki.test</string>
<key>CFBundleName</key>
<string>LOL</string>
</dict>
Then switch back to mobile and run:
uicache
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 you actually haven't written anything yet.
Actually writing a working app
So let's make a quick and dirty application really quick. 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 3 files: main.m, TestLabel.h, and TestLabel.m.
main.m
#import <UIKit/UIKit.h>
#import "TestLabel.h"
@interface LyAppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic, strong) UIWindow *window;
@end
int main(int argc, char *argv[])
{
@autoreleasepool
{
return UIApplicationMain(argc, argv, nil, NSStringFromClass(LyAppDelegate.class));
}
return 0;
}
@implementation LyAppDelegate
@synthesize window=_window;
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [UIWindow.alloc initWithFrame:UIScreen.mainScreen.bounds];
self.window.backgroundColor = UIColor.redColor;
UILabel *label = [[TestLabel alloc] initWithBackgroundColor:self.window.backgroundColor];
[self.window addSubview:label];
[label release];
[self.window makeKeyAndVisible];
return true;
}
@end
TestLabel.h
#import <UIKit/UIKit.h>
@interface TestLabel : UILabel
-(instancetype)initWithBackgroundColor:(UIColor *)backgroundColor;
@end
TestLabel.m
#import "TestLabel.h"
@implementation TestLabel
-(instancetype)initWithBackgroundColor:(UIColor *)backgroundColor
{
if(self == [self init])
{
self.backgroundColor = backgroundColor;
self.textColor = UIColor.whiteColor;
self.text = @"rofl";
self.frame = CGRectMake(20,20,300,300);
}
return self;
}
@end
Compiling
Run these commands:
clang -isysroot /var/mobile/sdks/latest \
-c main.m
clang -isysroot /var/mobile/sdks/latest \
-c TestLabel.m
clang -isysroot /var/mobile/sdks/latest \
-framework Foundation \
-framework UIKit \
main.o TestLabel.o \
-o Test
If you didn't get any errors, go ahead and open the app again and you should see this:
WAU, that AMAZING!!!
That's pretty much all you need to know to get started. If you want to use more frameworks (like AVFoundation or something) add the `-framework AVFoundation` flag during the last compile step (kinda like how I used UIKit and Foundation).
Other details
Icons, default backgrounds, entitlements, etc
In order to add an icon and support the longer screens, check out Apple's documentation on the subject. No need to write it twice. You can also look in any of the other `Info.plist`s in the /Applications/ directory on your device! Cydia.app would be a good place to start.
Uninstalling
Also in order to uninstall the application you need to delete it from /Applications/ and run `uicache` as mobile again. iOS thinks it's a system app, so you can't delete it like a normal iOS app.
glhf