想开发iPhone应用,没有Mac Book也没有Mac Mini,怎么办?
想尝试在Linux上开发iPhone吗,那就请接着往下看。
1. 前提条件:
在Ubuntu上编译好toolchain,参见我前面的文章。
因为不能跑模拟器,需要一部iPhone手机来测试程序,iPhone3或iPhone4都可以
(目前支持到iPhone 3.1SDK,程序可以在iPhone4上运行)
2. 从UIApplication派生你的应用程序类:
头文件MyScylla.h
m文件MyScylla.m
3. 定义自己的ViewController
CustomViewController.h
CustomViewController.m
4. 定义View
MyMainView.h
MyMainView.m
#import <UIKit/UIKit.h>
#import <UIKit/UIAlert.h>
#import "MyMainView.h"
@implementation MyMainView
@synthesize navBar;
@synthesize navItem;
@synthesize textView;
@synthesize button;
- (id)initWithFrame:(CGRect)rect {
self = [ super initWithFrame: rect ];
if (self != nil) {
NSLog(@"start initWithFrame");
isMuted = NO;
count = 0;
//navBar = [ self createNavBar: rect];
//[ self setNavBar ];
//[ self addSubView: [navBar view] ];
//NSLog(@"after add navBar");
CGRect rectText = CGRectMake(100,100,300,100);
textView = [ [ UITextView alloc] initWithFrame: rectText ];
//[ textView setTextSize: 12 ];
[ textView setText: @"Hello, world!" ];
[ self addSubview: textView ];
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
CGRect rect = CGRectMake(120,400,100,50);
//[sendButton setFrame:rect];
//sendButton = [ [ UIButton alloc] initWithFrame: rect];
button.frame = rect;
[button setTitle:@"Test" forState:UIControlStateNormal];
[button addTarget:self action:@selector(clickButton:)
forControlEvents:UIControlEventTouchUpInside];
//[button addTarget:self action:@selector(clickButton:forEvent:)
//forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
}
NSLog(@"end initWithFrame in MyMainView");
return self;
}
-(void)AlertWindow:(NSString *)transValue{
UIAlertView *alertView= [[UIAlertView alloc] initWithTitle:transValue message:transValue delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
- (UINavigationBar *)createNavBar: (CGRect) rect {
NSLog(@"start createNavBar");
UINavigationBar *newNav = [ [ UINavigationBar alloc]
initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)
];
[ newNav setDelegate: self ];
// add our title
navItem = [ [UINavigationItem alloc] initWithTitle: @"My Navigation" ];
[ newNav pushNavigationItem: navItem];
[ navItem setTitle: @"Another Example" ];
NSLog(@"end createNavBar");
return newNav;
}
- (void)setNavBar {
if(isMuted == YES) {
[ navItem setTitle: @"Spouse (Muted)"];
[ navBar showLeftButton:nil withStyle: 0 rightButton:@"Mute" withStyle: 1];
} else {
[ navItem setTitle: @"Spouse"];
[ navBar showLeftButton:nil withStyle: 0 rightButton:@"Mute" withStyle: 0];
}
NSLog(@"end setNavBar");
}
-(IBAction) clickButton :(id)inSender {
count++;
NSLog(@"clickButton");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Action invoked!" message:@"Button clicked!"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
-(IBAction) clickButton:(id)inSender forEvent:(UIEvent *)event {
NSLog(@"clickButton forEvent");
count++;
[inSender setTitle:[NSString stringWithFormat:@"count:%d", count]
forState:UIControlStateNormal];
}
/*
- (void)navigationBar: (UINavigationBar *)navbar buttonClicked:(int) button {
switch(button) {
case 1: // left
[ self AlertWindow: @"Left Button"];
break;
case 0: // right
[ self AlertWindow: @"Right Button"];
break;
}
}
*/
- (void)dealloc {
[textView release];
[navBar release];
[navItem release];
[super dealloc ];
}
@end
5. Makefile
6. 编译
ldid.sh:
export CODESIGN_ALLOCATE=/home/jack/iPhone/toolchain/toolchain/pre/bin/arm-apple-darwin9-codesign_allocate
ldid -S MyScylla