About | Buy | Forum | Industry Watch | Learning Curve | Products | Search | Twitter | Xnews
Home » Learning Curve » Developers Workshop

Hello iPhone

Put it all together, stir into a project, serve immediately. Finish off with an apple.

HelloApplication.h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <UIKit/UIApplication.h>
#import <UIKit/UIPushButton.h>
#import <UIKit/UITableCell.h>
#import <UIKit/UIImageAndTextTableCell.h>

@interface HelloApplication : UIApplication {
    UIImageAndTextTableCell *pbCell;
    UITableCell *buttonCell;
}
@end

HelloApplication.m

#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <UIKit/CDStructures.h>
#import <UIKit/UIPushButton.h>
#import <UIKit/UIThreePartButton.h>
#import <UIKit/UINavigationBar.h>
#import <UIKit/UIWindow.h>
#import <UIKit/UIView-Hierarchy.h>
#import <UIKit/UIHardware.h>
#import <UIKit/UITable.h>
#import <UIKit/UITableCell.h>
#import <UIKit/UITableColumn.h>
#import "HelloApplication.h"

@implementation HelloApplication
-(int)numberOfRowsInTable:(UITable *)table {
    return 2;
}
-(UITableCell *)table:(UITable *)table cellForRow:(int)row column:(int)col {
    return (row)? buttonCell: pbCell;
}
-(UITableCell *)table:(UITable *)table cellForRow:(int)row column:(int)col reusing:(BOOL)reusing {
    return pbCell;
}
-(void)applicationDidFinishLaunching:(id)unused {
    UIWindow *window;

    window = [[UIWindow alloc] initWithContentRect:[UIHardware fullScreenApplicationContentRect]];

    pbCell = [[UIImageAndTextTableCell alloc] init];
    [pbCell setTitle:@"Hello world!"];

    UIPushButton *button = [[UIThreePartButton alloc] initWithTitle:@"Touch Me"];
    buttonCell = [[UITableCell alloc] init];
    [buttonCell addSubview:button];
    [button sizeToFit];

    UITable *table = [[UITable alloc] initWithFrame:CGRectMake(0f, 48f, 320f, 432f)];
    UITableColumn *col = [[UITableColumn alloc] initWithTitle:@"HelloApp" identifier:@"hello" width:320f];

    [window orderFront:self];
    [window makeKey:self];
    [window _setHidden:NO];

    [table addTableColumn:col];
    [table setDataSource:self];
    [table setDelegate:self];
    [table reloadData];

    UINavigationBar *nav = [[UINavigationBar alloc] initWithFrame:CGRectMake(0f, 0f, 320f, 48f)];
    [nav showButtonsWithLeftTitle:@"Foo" rightTitle:@"Bar" leftBack:YES];
    [nav setBarStyle:0];

    struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
    rect.origin.x = rect.origin.y = 0f;
    UIView *mainView;
    mainView = [[UIView alloc] initWithFrame:rect];
    [mainView addSubview:nav];
    [mainView addSubview:table];

    [window setContentView:mainView];
}
@end

Makefile

CC=arm-apple-darwin-cc
LD=$(CC)
LDFLAGS=-lobjc -framework CoreFoundation -framework Foundation -framework UIKit -framework LayerKit

all:    Hello

Hello:  hello.o HelloApplication.o
        $(LD) $(LDFLAGS) -o $@ $^

%.o:    %.m
                $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

clean:
                rm -f *.o Hello

hello.m

int main(int argc, char *argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    return UIApplicationMain(argc, argv, [HelloApplication class]);
}

Info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleExecutable</key>
    <string>Hello</string>
    <key>CFBundleIdentifier</key>
    <string>net.fiveforty.iphone.hello-uikit</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>SBUsesNetwork</key>
    <integer>3</integer>
</dict>
</plist>

See Also
iPhone
Alpine Dottie
Effective UID: 0
iPhone Ramdisk
iPhone and Security
iPhone and the Media
iPhone and Full Disclosure
iPhone Hack to be Patched
iPhone OS X System Architecture
iPhone Bootloader: Hackint0sh Progress Report

Thanks to Devon at Pixel Groovy for the excellent artwork.

About | Buy | Forum | Industry Watch | Learning Curve | Products | Search | Twitter | Xnews
Copyright © Rixstep. All rights reserved.