Monday, December 22, 2008

iPhone SDK 2.2 API Explorer

API Explorer is an iPhone App for searching SDK API, version 1 is written by Patrick Collison

http://collison.ie/blog/2008/10/iphone-hackery-api-explorer

git clone http://code.collison.ie/git/explorer/.git

I have enhanced it to version 1.2.1 with addition of searchbox and on-line reference to Erica Sadun 2.2 class documentation
and some bug fixes

Installation Instructions:

Cydia Source : http://cydia.iphone.org.hk/apt/
Section: Utilities
Name: API Explorer

Source code for version 1.2.1 is here
http://www.iphone.org.hk/attach/48276-explorer-1.2.1.zip

SVN repository is here
http://code.google.com/p/apiexplorer/





Saturday, December 20, 2008

property and synthesize directives in Objective C 2.0

@property directive is to declare a property

@interface Test : NSObject {
}
@property (readwrite,assign) int var1
@property (readonly,assign) int var2
@property (getter=foo, setter=foo1:) int var3
@end

readwrite attribute (default) tells the compiler to generate both getter and setter accessors

readonly attribute tells the compiler not to generate a setter accessor

assign attribute to implement set-by-assignment (i.e. generate setter and simply assigns a value to the instance variable)

-(void) setVar1:(NSString *)s
{
var1 = s;
}


copy attribute to implement set-by-copy (usually for mutable object)

-(void) setVar1:(NSString *)s
{
[var1 release];
var1 = [s copy];
}


retain attribute to implement set-by-retainment (i.e. generate setter and retain a value before assignment)

-(void) setVar1:(NSString *)s
{
[s retain];
[var1 release];
var1 = s;
}



@synthesize directive is to make the compiler generate accessors

@implementation Test
@synthesize var1;
@synthesize var2;
@dynamic var3;
@end

By Default, these messages are named var1 and setVar1 where var1 is the name of the variable



dynamic attribute tells the compiler not to generate any accessor messages









Here is a good guideline for memory management in Cocoa
http://oreilly.com/pub/a/mac/excerpt/Cocoa_ch04/index.html

Retention Count rules
  • Within a given block, the use of -copy, -alloc and -retain should equal the use of -release and -autorelease.
  • Objects created using convenience constructors (e.g. NSString's stringWithString) are considered autoreleased.
  • Implement a -dealloc method to release the instance variables you own

  • retain increases the reference count of an object by 1
  • release decreases the reference count of an object by 1
  • autorelease decreases the reference count of an object by 1 at some stage in the future
  • alloc allocates memory for an object, and returns it with retain count of 1
  • copy makes a copy of an object, and returns it with retain count of 1






How-To compile iPhone Project in Mac using Makefile instead of Xcode and fake codesign and then install to pwned iPhone

You can use the command line xcodebuild to build and install iPhone project such as

xcodebuild -target Project_Name
xcodebuild install -target Project_Name


Here is an example to compile iPhone Project using Makefile instead of XCode.

The Makefile will compile and codesign the binary using ldid (Intel binary version) and then install the files directly to iPhone /Applications/ folder using ssh

Location of files
----------------
Classes : source code (.m .c .cpp etc)
Resources : png file and other support files
Project folder : *.xib Info.plist

(1) First you need to download this sample zip file and extract it to your Mac and cd to the directory


curl -O http://www.iphone.org.hk/attach/48150-PeoplePickerDemo.zip
unzip 48150-PeoplePickerDemo.zip
cd PeoplePickerDemo


(3) Change the IPHONE_IP in the Makefile to the IP address of iPhone, default is 10.0.2.2


Makefile: Select all

IPHONE_IP=10.0.2.2

SDKVER=2.0
SDK=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$(SDKVER).sdk

CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.0.1
CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-g++-4.0.1
LD=$(CC)

LDFLAGS += -framework CoreFoundation
LDFLAGS += -framework Foundation
LDFLAGS += -framework UIKit
LDFLAGS += -framework CoreGraphics
LDFLAGS += -framework AddressBookUI
LDFLAGS += -framework AddressBook
//LDFLAGS += -framework QuartzCore
//LDFLAGS += -framework GraphicsServices
//LDFLAGS += -framework CoreSurface
//LDFLAGS += -framework CoreAudio
//LDFLAGS += -framework Celestial
//LDFLAGS += -framework AudioToolbox
//LDFLAGS += -framework WebCore
//LDFLAGS += -framework WebKit
//LDFLAGS += -framework SystemConfiguration
//LDFLAGS += -framework CFNetwork
//LDFLAGS += -framework MediaPlayer
//LDFLAGS += -framework OpenGLES
//LDFLAGS += -framework OpenAL

LDFLAGS += -L"$(SDK)/usr/lib"
LDFLAGS += -F"$(SDK)/System/Library/Frameworks"
LDFLAGS += -F"$(SDK)/System/Library/PrivateFrameworks"

CFLAGS += -I"/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/gcc/arm-apple-darwin9/4.0.1/include/"
CFLAGS += -I"$(SDK)/usr/include"
CFLAGS += -I"/Developer/Platforms/iPhoneOS.platform/Developer/usr/include/"
CFLAGS += -I"/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator$(SDKVER).sdk/usr/include"
CFLAGS += -DDEBUG -std=c99
CFLAGS += -Diphoneos_version_min=2.0
CFLAGS += -F"$(SDK)/System/Library/Frameworks"
CFLAGS += -F"$(SDK)/System/Library/PrivateFrameworks"

CPPFLAGS=$CFLAGS


(4) install respring utility in iPhone
make install_respring

(5) run make and make install
make
make install


(6) Test launch the app Demo in iPhone
.
.
.

In order to avoid typing the password using ssh, you can install the ssh public key of your Mac to your iPhone using the following method

(a) keygen in Mac terminal and type (if you haven't generated it before)
ssh-keygen -t rsa

You will be asked to enter a passphrase, please remember that if you enter that.

(b) create .ssh directory in iPhone (assume ip address of iPhone is 10.0.2.2) and in Mac terminal and type
ssh root@10.0.2.2 'mkdir -p .ssh'
then enter iPhone root password (alpine)

(c) copy mac public key to iPhone, and in Mac Terminal type
cat ~/.ssh/id_rsa.pub | ssh root@10.0.2.2 'cat >> .ssh/authorized_keys'
then enter iPhone root password (alpine)

(d) Edit the file /etc/ssh/sshd_config in iPhone

change these

#StrictModes yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys


to


StrictModes no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys


(e)reboot iPhone

If you don't reboot, you can restart sshd using

cd /Library/LaunchDaemons/
launchctl unload com.openssh.sshd.plist ; launchctl load com.openssh.sshd.plist



To compile ldid in Power PC, do this


wget http://svn.telesphoreo.org/trunk/data/ldid/ldid-1.0.476.tgz

tar -zxf ldid-1.0.476.tgz

# this patch is for PowerPC only
wget -qO- http://fink.cvs.sourceforge.net/viewvc/*checkout*/fink/dists/10.4/unstable/crypto/finkinfo/ldid.patch?revision=1.1 | patch -p0


cd ldid-1.0.476

g++ -I . -o util/ldid{,.cpp} -x c util/{lookup2,sha1}.c

sudo cp -a util/ldid /usr/bin







Tuesday, December 2, 2008

Touch Fighter 2 source code



A 2 week, 10,000+ lines coding done by Apple to demonstrate the graphics and audio capabilities of the iPhone for gaming.
YouTube: iPhone SDK Demo - Touch Fighter

The link may only be for Tech Talk attendees or ADC Member but if it works for you, enjoy.

Here is the link to download.
https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?fileID=24200

.
.
.