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

.
.
.

Thursday, November 27, 2008

iPhone SDK 2.2 header files dump is here

http://ericasadun.com/iPhoneDocs220/

MPTVOutWindow video code demo is here
http://www.appleinsider.com/articles/08/11/26/iphone_2_2_hides_video_out_code_for_third_party_apps.html

and the perl script to generate header files
http://arstechnica.com/journals/apple.ars/2008/11/24/dumping-the-iphone-2-2-frameworks


Alternatively you can classdump in iPhone

(1) Install class-dump in Cydia / apt-get
apt-get install class-dump

(2) run this script in iPhone to generate the header files in current directory
dump.sh: Select all

#/bin/bash
for FRAMEWORKS in Frameworks PrivateFrameworks; do
frameworklib=/System/Library/"${FRAMEWORKS}"
for frameworkpath in "${frameworklib}"/*.framework; do
frameworkdir="$(basename "${frameworkpath}")"
frameworkbin="${frameworkdir%.*}"
if [ -f "${frameworkpath}/${frameworkbin}" ]; then
echo "Framework: ${frameworkbin}"
mkdir -p ${frameworkbin}
class-dump -H -o "${frameworkbin}" "${frameworkpath}/${frameworkbin}"
fi
done
done


(3) If you want to remove all header directories under current directory and start over again run
find . -type d -name '[a-zA-Z]*' -print | xargs rm -rf
.
.
.
.
.

Sunday, November 23, 2008

How to skip provisioning profile for iPhone SDK 2.2 (build 9M2621)

The trick to skip provisioning profile still works

Just backup and edit the file

/Developer/Platforms/iPhoneOS.platform/Info.plist

and add the magic words in red as below

<key>NATIVE_ARCH</key>
<string>armv6</string>
<key>PLIST_FILE_OUTPUT_FORMAT</key>
<string>binary</string>
<key>PROVISIONING_PROFILE_ALLOWED</key>
<string>NO</string>
<key>PROVISIONING_PROFILE_REQUIRED</key>
<string>NO</string>

<key>SDKROOT</key>
<string>iphoneos2.2</string>


Please remember to restart your Xcode after the amendment above.

I have tested it to build app on jailbreaked iPhone firmware 2.1 & 2.2

For MobileInstallation patch, please use my package as posted here
http://hackint0sh.org/forum/showpost.php?p=340693&postcount=14

Updated Notes
If you have "security policy error" after Build & Go. Do these steps

(1) Install a new free app from App Store in iPhone (not sync from iTunes)
(2) Launch that newly purchased free app and then close it.
(3) Reboot your iPhone (that is power off and on again)
(4) Launch the app again that you have Build & Go in Xcode to iPhone.

Please also refer to the latest article for SDK2.2.1
http://iphonesdkdev.blogspot.com/2009/01/how-to-skip-provisioning-profile-for.html




Tuesday, November 4, 2008

Upgrade VMWare Image to Ubuntu 8.10 for iPhone open toolchain SDK2.0 / Android SDK development

(1) Download ubuntu-8-1.10-desktop-i386.iso (32 bit Intel i386 Desktop)
http://www.ubuntu.com/getubuntu/download
MD5 (ubuntu-8-1.10-desktop-i386.iso) = 24ea1163ea6c9f5dae77de8c49ee7c03

Installation is very easy just mount the iso image in the VMWare, and everything goes default. then install VMWare tools. If network does not work try command "sudo dhclient"

(2) VMWare Settings : Harddisk Size 8G, Ram 512MB

(3) Purpose : sdk development on iPhone / Android
Allows samba mount, ssh / scp access
apache2 server with php5 support for sqlite3 db

(4) Add root access for useraccount without password (this does not work, I don't know why, so you still need password)
Ubuntu default root disabled, so you can disable password input by editing etc/sudoers
sudo visudo
Add this line (e.g. sdkuser is the default user account)
sdkuser ALL=(ALL) NOPASSWD:ALL

(5) install build essential packages so that you can compile llvm-gcc for iPhone toolchain SDK2.0

sudo apt-get update
sudo apt-get install build-essential bison flex


(6) install server packages so that you can have local webserver and ssh and samba server

sudo apt-get install apache2 php5 libapache2-mod-php5 php5-cli php5-common php5-cgi php5-sqlite openssh-server samba


Install php5-sqlite3
sudo apt-get install php-db php-pear
wget http://us.archive.ubuntu.com/ubuntu/pool/universe/p/php-sqlite3/php-sqlite3_0.5-1_i386.deb
sudo dpkg -i php-sqlite3_0.5-1_i386.deb


(7) Create Project folder for smb mount (guest login ok) so that you can use windows / smb mount the virtual machine folder

(assume sdkuser is the default user account)


mkdir -p /home/sdkuser/Projects
chmod 777 /home/sdkuser/Projects

sudoedit /etc/samba/smb.conf


and add the followings at the end

smb.conf: Select all

[Projects]
comment = Projects Folder Share
writable = yes
locking = no
path = /home/sdkuser/Projects
public = yes
browseable = yes
guest ok = yes
create mask = 0666
directory mask = 0777


Note : you have to restart samba server to make the new configuration effective
sudo /etc/init.d/samba restart

(8) install jdk6 so that you can compile Andriod app

sudo apt-get install sun-java6-jdk



(9) Download Android SDK http://dl.google.com/android/android-sdk-linux_x86-1.0_r1.zip from http://code.google.com/android/download_list.html

install in ~/Android/

mkdir -p ~/Android/
sudo unzip ~/Desktop/android-sdk-linux_x86-1.0_r1.zip -d ~/Android/
sudo chown -R sdkuser:sdkuser ~/Andriod


create sd card & test emulator

~/Android/android-sdk-linux_x86-1.0_r1/tools/mksdcard -l SD500M 500M ~/Android/sd500m.img

~/Android/android-sdk-linux_x86-1.0_r1/tools/emulator -datadir ~/Android -scale 0.7 -sdcard ~/Android/sd500m.img &


(10) Download and Install Eclipse 3.4.1 (you can't use the debian package eclipse which is 3.2 only)
from http://www.eclipse.org/downloads/
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/ganymede/SR1/eclipse-java-ganymede-SR1-linux-gtk.tar.gz

install in /usr/lib

cd /usr/lib; sudo tar -xzvf ~/Desktop/eclipse-java-ganymede-SR1-linux-gtk.tar.gz


Add main menu & icon for eclipse in GNOME


sudoedit /usr/share/applications/eclipse.desktop


and save this

eclipse.desktop: Select all

[Desktop Entry]
Name=Eclipse
Comment=Develop applications in a variety of different programming languages
Exec=/usr/lib/eclipse/eclipse
Icon=eclipse48.png
Terminal=false
Type=Application
Categories=Development;
StartupNotify=true


There is no eclipse icon in the download file eclipse-java-ganymede-SR1-linux-gtk.tar.gz. You can get it from eclipse 3.2.2 package
and install it manually

download the eclipse 3.2.2 package
wget http://us.archive.ubuntu.com/ubuntu/pool/universe/e/eclipse/eclipse_3.2.2-5ubuntu2_i386.deb

extract the package and copy the icons to /usr/share/pixmaps/
dpkg -x eclipse_3.2.2-5ubuntu2_i386.deb tmp
sudo cp tmp/usr/share/pixmaps/* /usr/share/pixmaps/
rm -fr tmp


Install Android sdk plug-in for Eclipse
(based on http://code.google.com/android/intro/installing.html#installingplugin)
add this site and install in Eclipse
http://dl-ssl.google.com/android/eclipse/

Edit Eclipse's preference for Andriod (Window -> Preferences -> Android)

SDK location
/home/sdkuser/Android/android-sdk-linux_x86-1.0_r1/

emulator options
-scale 0.7 -sdcard /home/sdkuser/Android/sd500m.img

Test HelloActivity in Eclipse
(a) Create a New Android Project in Eclipse (File -> New -> Project... -> Android -> Android Project)
(b) Choose Create project from existing source and browse to ~/Android/android-sdk-linux_x86-1.0_r1/samples/HelloActivity
(c) Run HelloActivity as Android Application
(d) Then the emulator will start Hello, World! will be on the emulator screen

Note: Please don't set the workspace of Eclipse to the sample project folder
~/Android/android-sdk-linux_x86-1.0_r1/samples/
or else you will get error when importing project from existing source


(11) Install iPhone llvm-gcc and toolchain SDK2.0
Refer to this article and download the file UpgradeToolChain2.tgz and build the llvm-gcc for iPhone
http://iphonesdkdev.blogspot.com/2008/10/how-to-install-llvm-gcc-for-iphone-sdk.html


Install ldid in Linux, so that you can fake codesign it

cd ~/Projects
wget http://svn.telesphoreo.org/trunk/data/ldid/ldid-1.0.476.tgz
tar -zxf ldid-1.0.476.tgz
cd ldid-1.0.476
g++ -I . -o util/ldid{,.cpp} -x c util/{lookup2,sha1}.c
sudo cp -a util/ldid /usr/bin


If you need to codesign the iPhone binary in Linux add this (as one line) to your build script

export CODESIGN_ALLOCATE=/usr/toolchain2/pre/bin/arm-apple-darwin9-codesign_allocate; ldid -S $(PROJECTNAME)



(12) test apache2 and php so that you can see the php info page in the local webserver

In Firefox browser of Ubuntu enter this address
http://localhost/

enable php5 (sometimes you need this)
a2enmod php5

restart apache server
sudo /etc/init.d/apache2 restart

create this test.php script in /var/www

sudo chown -R sdkuser:sdkuser /var/www
echo "<?php phpinfo(); ?>" > /var/www/test.php


and see the php info in Firefox browser of Ubuntu
http://localhost/test.php

(13) create sqlite3 db
sqlite3 test.db: Select all


sudo chown -R sdkuser:sdkuser /var/www
cd /var/www
sqlite3 test.db
sqlite> create table test (id integer primary key, value text);
sqlite> insert into test (value) values('eenie');
sqlite>
sqlite> insert into test (value) values('meenie');
sqlite> insert into test (value) values('miny');
sqlite> insert into test (value) values('mo');
sqlite> select * from test;
sqlite>
sqlite> .exit


and test sqlite3 & php5-sqlite3 by using testdb.php script to test the access to sqlite3 db on webserver

(14) testdb.php
testdb.php: Select all


<// Version 0.01
<html>
<head><meta http-equiv="Content-Type" content="text-html; charset=UTF-8" /></head>
<title>iPhone Database</title>
<body>
<?php

$ip_dbpath[] = '/var/www/test.db';

// $ip_dbpath[] = '/var/www/sms.db';
// $ip_dbpath[] = '/var/www/call_history.db';
// $ip_dbpath[] = '/var/www/notes.db';
// $ip_dbpath[] = '/var/www/AddressBook.sqlitedb';
// $ip_dbpath[] = '/var/www/Calendar.sqlitedb';

// db location in iPhone /private/var/mobile/Library/SMS/sms.db
// db location in iPhone /private/var/mobile/Library/CallHistory/call_history.db
// db location in iPhone /private/var/mobile/Library/Notes/notes.db
// db location in iPhone /private/var/mobile/Library/AddressBook/AddressBook.sqlitedb
// db location in iPhone /private/var/mobile/Library/Calendar/Calendar.sqlitedb


$ip_dbdesc[] = 'test';

// $ip_dbdesc[] = 'SMS';
// $ip_dbdesc[] = 'Call History';
// $ip_dbdesc[] = 'Notes';
// $ip_dbdesc[] = 'Address Book';
// $ip_dbdesc[] = 'Calendar';

$ip_query[] = 'SELECT * from test order by 1';
// $ip_query[] = 'SELECT date, address, text FROM message order by 1 desc, 2;';
// $ip_query[] = 'SELECT date, address, duration FROM call order by 1 desc;';
// $ip_query[] = 'SELECT creation_date, data, title FROM Note inner join note_bodies on Note.ROWID = note_bodies.note_id order by 1;';
// $ip_query[] = 'SELECT First, Last, Middle, CreationDate, ModificationDate FROM ABPerson;';
// $ip_query[] = 'SELECT start_date, end_date, summary, location, description FROM Event order by 1, 2;';

// $dbcount = sizeof($ip_dbpath);
// if you uncomment the above db & query and add copy the iPhone db , you can list out the content of sqlitedb of iPhone
$dbcount = 1;

for ($dbnum=0;$dbnum<$dbcount;$dbnum++){

try {
$dbpath = $ip_dbpath[ $dbnum ];
$dbh = new PDO('sqlite:'.$dbpath);
$query = $ip_query[ $dbnum ];
$stmt = $dbh->prepare($query);
$stmt->execute();
}
catch (PDOException $e) {
die("Could not open database" . $e->getMessage());
}
$colcount = $stmt->columnCount();
echo "<h1>". $ip_dbdesc[ $dbnum ] . "</h1>";
echo "<table cellpadding=10 border=1>";

for ($i=0;$i<$colcount;$i++) {
$meta = $stmt->getColumnMeta($i);
echo "<td>".$meta["name"]."</td>";
}

while ($row = $stmt->fetch()) {
echo "<tr>";
for ($i=0;$i<$colcount;$i++) {
$meta = $stmt->getColumnMeta($i);
if ($meta["native_type"] == "null") {
echo "<td> </td>";
}
elseif (preg_match("/date$/i", $meta["name"])) {
echo "<td>". date("j M Y D g.i a", $row[$i])."</td>";
}
elseif (preg_match("/[call|sms]$/i", $meta["name"]) && $meta["name"] == "address" && strlen(rtrim($row[ $i])) == 8) {
echo "<td><A href='Tel:".$row[$i]."'>".$row[$i]."</A></td>";
}
else {
echo "<td>".$row[ $i]."</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
?>
</body>
</html>


(15) Enjoy building app




Why to install apache2, php5 and php5-sqlite3 in Ubuntu ?

Because both iPhone and Andriod SDK use sqlite3 as database engine.
Webserver can be served for many purposes when testing including http get/post access and cydia repository as well.



Additional Notes
If you need to install flash plugin in firefox
sudo apt-get install flashplugin-nonfree

If you need to install java plugin in firefox
sudo apt-get install sun-java6-plugin

If you need to install xpdf
sudo apt-get install xpdf-reader

If you need to install jedit
sudo apt-get install jedit

Install Ubuntu in Virtual PC 2007

The above installation can also be applied for Virtual PC2007 if you use Windows OS. One problem of Ubuntu in VPC 2007 is that "sound does not work"

Install Ubuntu in Virtual PC 2007 may have screen display problem (similar to Fedora) and fail during installation.

Here are the steps to successfully install Ubuntu in Virtual PC 2007.

(1) Setup the new Virtual Machine in VPC 2007 and mount the iso image (ubuntu-8-1.10-desktop-i386.iso).

(2) Inside the Ubuntu Install Screen, first Press "F4" and Select "Safe Graphics mode"

(3) Then press down arrow and highlight the menu "Install Ubuntu". (highlight only and don't press Enter)

(4) Press "F6" to bring up the "Other Options"
Then type "vesa vga=771" at the end of the option line
Then Press "Enter", the installation will start instantly.

Note: If you want other resolution, you can try say vga=791 instead of vga=771

I did not try all these, some of them might not work. The codes are listed out for reference only.

vga=769 means 600x480 8 bits color
vga=785 means 600x480 16 bits color
vga=786 means 600x480 24 bits color
vga=771 means 800x600 8 bits color
vga=788 means 800x600 16 bits color
vga=789 means 800x600 24 bits color
vga=773 means 1024x768 8 bits color
vga=791 means 1024x768 16 bits color
vga=792 means 1024x768 24 bits color


(5) After installation, it will prompt to restart. But the restart might not work and you have to manually reset the VM in VPC 2007

(6) Then release the mounted iso image and in VPC 2007 menu to reset the VM that is in VPC 2007 menu do Action -> Reset

(7) Enjoy using Ubuntu in VPC 2007



(8) To solve the sound problem in VPC2007, start the Terminal in Ubuntu and type

sudoedit /etc/rc.local

At the end of the # lines, but before “exit 0″, type on a new line (again without quotes) “modprobe snd-sb16″
Ctrl + O to write out, enter to accept the name, Ctrl + X to close.

Saturday, October 18, 2008

[How-To] Install llvm-gcc for iPhone SDK 2.0 in Linux

The building of iPhone gcc in Linux is described in
http://www.saurik.com/id/4

But this guide involved a lot of downloading and patching, so I put all the downloading in one zipped tar file. All you have to do is download it and run the build script in your Linux

I used the Asus eeepc Linux as an example, but others Linux variant / cygwin should be very similar.

Asus eeepc comes with xandros Debian Linux but does not have development tools. This part(A) shows you how to setup the development tools first. Other Linux variant does have development tools and you might want to skip this part and continue on Part B

(A) Install the development tools in eeepc

(1) Launch Terminal (Ctrl-Alt-T) in eeepc

(2) edit the file/etc/apt/sources.list
sudo vi /etc/apt/sources.list

and add this line to the end of the file "sources.list"
deb http://http.us.debian.org/debian/ stable main

(3) Run these commands in Terminal to install building tools

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential bison flex


(B) Download the file to your Linux
UpgradeToolChain2.tgz

The package is very large (about 200M)
You should first goto this websever
http://www.iphonefix.de/

and click the DOWNLOADS menu
and username password is generated for every visitor on the fly when you click on the ftp sever link

Inside the ftp server goto the folder
iPhoneToolchain VMWare Image / V3
and download the file UpgradeToolChain2.tgz

MD5 (UpgradeToolChain2.tgz) = b373c0e600d45b1019e2894614b5979b
Size (UpgradeToolChain2.tgz) = 202278454




and extract to /usr

cd /usr
sudo tar -xzvf ~/UpgradeToolChain2.tgz


(C) login in as superuser and build the Darwin CC tools and llvm-gcc in Linux

su
cd /usr/toolchain2
./build_20.sh

wait for 10+ minutes to complete the building of tools and gcc

If you extract the tgz to different folder and want to build it in some other folder, please modify the environment variable toolchain in build_20.sh

(D) Test build your project in Linux
The include files have the iPhone SDK headers so you can test it using some available open source project (without Interface Builder) that using SDK 2.0 headers

If you want ti upgrade to SDK 2.1/2.2 headers just copy and replace the 2.0 headers.

For example, download this WinterBoard App Source code from the developer and compile it in Linux

wget http://svn.saurik.com/repos/menes/trunk/winterboard/Application.mm

/usr/toolchain2/pre/bin/arm-apple-darwin9-g++ -g0 -O2 -Wall -Werror -o WinterBoard Application.mm \
-framework UIKit -framework Foundation -framework CoreFoundation -lobjc -framework CoreGraphics


If you want to deploy the app to iPhone, you have to codesign it (using ldid in iPhone) and provide the additional required project file in the .app folder e.g. (Info.plist, Icon.png etc)

Enjoy compiling and building iPhone App

Moreover, I have modified a previous VMWare image based on Debian Linux and build the llvm-gcc for iPhone and the toolchain and SDK20 headers there. If you have VMWare workstation or player / VMWare Fusion (Mac OS X), you can use it to build 2.0 iPhone app using ssh or samba mount access. The VMWare image is very large (about 1.2G compressed).

You should first goto this websever
http://www.iphonefix.de/

and click the download menu
and username password is generated for every visitor on the fly when you click on the ftp sever link

Inside the ftp server goto the folder
iPhoneToolchain VMWare Image / V3



and download the file
iPhoneToolchian_SDK20.rar

MD5 (iPhoneToolchain_SDK20.rar) = 29888ad8a73cf0a9674152c64961c02a
Size (iPhoneToolchain_SDK20.rar) = 1304054096

unrar the file and then use VMWare workstation or VMWare Fusion to open it

login: root
password: toolchain

The instructions are in the README.txt There are 3 sample projects inside the VMWare image

new!!
Install ldid in Linux, so that you can fake codesign it

cd ~/Projects
wget http://svn.telesphoreo.org/trunk/data/ldid/ldid-1.0.476.tgz
tar -zxf ldid-1.0.476.tgz
cd ldid-1.0.476
g++ -I . -o util/ldid{,.cpp} -x c util/{lookup2,sha1}.c
sudo cp -a util/ldid /usr/bin


Updates : The source of of ldid is moved to here
wget http://www.telesphoreo.org/export/477/trunk/data/ldid/ldid-1.0.476.tgz
or updated one here
wget http://svn.telesphoreo.org/trunk/data/ldid/ldid-1.0.610.tgz

Updates : If you compiled it in cgywin, you need to add (uint32_t) in the source code ldid.cpp that has ambiguous overload call error message like this

error: call of overloaded 'Swap(int)' is ambiguous



If you need to codesign the iPhone binary in Linux add this (as one line) to your build script

export CODESIGN_ALLOCATE=/usr/toolchain2/pre/bin/arm-apple-darwin9-codesign_allocate; ldid -S $(PROJECTNAME)

A sample Makefile for Linux toolchain

Makefile: Select all

# Makefile for gcc compiler for Linux iPhone toolchain (SDK Headers)

PROJECTNAME=HelloWorld
APPFOLDER=$(PROJECTNAME).app
INSTALLFOLDER=$(PROJECTNAME).app

IPHONE_IP=10.0.2.2

SDK=/usr/toolchain2/sys
CC=/usr/toolchain2/pre/bin/arm-apple-darwin9-gcc
LD=$(CC)
LDFLAGS += -arch arm -lobjc
LDFLAGS += -framework CoreFoundation
LDFLAGS += -framework Foundation
LDFLAGS += -framework UIKit
LDFLAGS += -framework CoreGraphics
//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 += -isysroot $(SDK)
LDFLAGS += -F"$(SDK)/System/Library/Frameworks"
LDFLAGS += -F"$(SDK)/System/Library/PrivateFrameworks"
LDFLAGS += -bind_at_load
LDFLAGS += -multiply_defined suppress
LDFLAGS += -march=armv6
LDFLAGS += -mcpu=arm1176jzf-s

CFLAGS += -isysroot $(SDK)
CFLAGS += -DDEBUG -Wall -std=c99
CFLAGS += -Diphoneos_version_min=2.0

BUILDDIR=./build/2.0
SRCDIR=./Classes
RESDIR=./Resources
OBJS+=$(patsubst %.m,%.o,$(wildcard $(SRCDIR)/*.m))
OBJS+=$(patsubst %.c,%.o,$(wildcard $(SRCDIR)/*.c))
OBJS+=$(patsubst %.m,%.o,$(wildcard ./*.m))
RESOURCES=$(wildcard $(RESDIR)/*)
RESOURCES+=$(wildcard ./*.png)

all: $(PROJECTNAME)

$(PROJECTNAME): $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^

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

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

dist: $(PROJECTNAME)
rm -rf $(BUILDDIR)
mkdir -p $(BUILDDIR)/$(APPFOLDER)
cp -r $(RESOURCES) $(BUILDDIR)/$(APPFOLDER)
cp Info.plist $(BUILDDIR)/$(APPFOLDER)/Info.plist
@echo "APPL????" > $(BUILDDIR)/$(APPFOLDER)/PkgInfo
export CODESIGN_ALLOCATE=/usr/toolchain2/pre/bin/arm-apple-darwin9-codesign_allocate; ldid -S $(PROJECTNAME)
cp $(PROJECTNAME) $(BUILDDIR)/$(APPFOLDER)

install: dist
ping -t 3 -c 1 $(IPHONE_IP)
ssh root@$(IPHONE_IP) 'rm -fr /Applications/$(INSTALLFOLDER)'
scp -r $(BUILDDIR)/$(APPFOLDER) root@$(IPHONE_IP):/Applications/$(INSTALLFOLDER)
ssh root@$(IPHONE_IP) 'respring'
@echo "Application $(INSTALLFOLDER) installed"

uninstall:
ping -t 3 -c 1 $(IPHONE_IP)
ssh root@$(IPHONE_IP) 'rm -fr /Applications/$(INSTALLFOLDER); respring'
@echo "Application $(INSTALLFOLDER) uninstalled"

clean:
@rm -f $(SRCDIR)/*.o
@rm -rf $(BUILDDIR)
@rm -f $(PROJECTNAME)






Friday, September 19, 2008

Xcode Template for pwned iPhone device updated to version 3.5.2

This Xcode Template is now updated to version 3.5.2

To install, run these in Mac Terminal (assume you have installed the Xcode in /Developer folder)


curl -O http://apiexplorer.googlecode.com/files/ToolChainTemplate_v352.zip
unzip -o ToolChainTemplate_v352.zip -d "/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates"

MD5 (ToolChainTemplate_v352.zip) = 5de15c4cc9f7bab7feeafff5f121da36



There are 4 new project templates to build the command line utility for iPhone
C++ Tool (.cpp)
CoreFoundation Tool (.c)
Foundation Tool (.m)
Objective C++ Tool (.mm)


These 4 command line utility templates used wifi connection to install compiled binary in your iPhone, so you need not connect your iPhone via usb port and MobileInstallation patch is not needed.

Requirements & Info:
(1) Default use Open toolchain headers
(2) iPhone and Mac connected to wifi (you should change the IPHONE_IP in Project Settings)
(3) Open SSH and Link Indenty Editor installed in iPhone
(4) Mac's ssh key installed in iPhone
(5) Debug / Release build to iPhone folder /private/var/root (no Build & Go) and you should change IPHONE_INSTALL_DIR in the Project Settings
(6) Cannot build to Simulator

Xcode Template Version 3.5.2 adds a Static Library Template for iPhone
To build the Universary Library for i386 and arm
First build it on "Device" "Release"
Second build it on "Simulator" "Release"
Then the Universary Library binary will be in the project directory
To examine the content of the Universary Library binary, run ./otoolprint.sh in the project folder


Open Tool Chain Application
This template uses open toolchain headers provides a starting point for any application without Interface Builder.

Requirements and Info:
(1) No Interface Builder
(2) Default use open toolchain headers
(3) For pwned iPhone / iPod Touch with patched MobileInstallation
(4) codesign certificate "iPhone Pwned Developer" installed in Mac
(5) XCode SDK Info.plist Setting has removed Provisioning Profile requirement
(6) Cannot build to Simulator


View-Based Application
This template provides a starting point for an application that uses a single view. It provides a view controller to manage the view, and a nib file that contains the view.

Requirements and Info:
(1) Default use official iPhone SDK headers
(2) For pwned iPhone / iPod Touch with patched MobileInstallation
(3) codesign certificate "iPhone Pwned Developer" installed in Mac
(4) XCode SDK Info.plist Setting has removed Provisioning Profile requirement

Window-Based Application
This template provides a starting point for any application without Interface Builder and provides a minimal iPhone application with a single view, ready for customizing.
This is a good starting point for your first application. In the UIView subclass, you can implement methods to draw content on the screen and to respond to touches. In a more full-featured application, you typically add a view controller to handle data and to manage rotation.

Requirements and Info:
(1) No Interface Builder
(2) Default use official iPhone SDK headers
(3) For pwned iPhone / iPod Touch with patched MobileInstallation
(4) codesign certificate "iPhone Pwned Developer" installed in Mac
(5) XCode SDK Info.plist Setting has removed Provisioning Profile requirement

Updated Notes
If you have "security policy error" after Build & Go. Do these steps

(1) Install a new free app from App Store in iPhone (not sync from iTunes)
(2) Launch that newly purchased free app and then close it.
(3) Reboot your iPhone (that is power off and on again)
(4) Launch the app again that you have Build & Go in Xcode to iPhone.

Thursday, September 18, 2008

[Firmware 2.1] How to skip provisioning profile for iPhone SDK

How to skip provisioning profile for iPhone SDK (build 9M2517) for firmware 2.1

First close your Xcode and backup the iPhoneOS.platform Info.plist by running this in Mac Terminal


sudo cp -p /Developer/Platforms/iPhoneOS.platform/Info.plist /Developer/Platforms/iPhoneOS.platform/Info.plist.bak


Then edit the iPhoneOS.platform Info.plist file

sudo vi /Developer/Platforms/iPhoneOS.platform/Info.plist


and change

<key>PROVISIONING_PROFILE_ALLOWED</key>
<string>YES</string>
<key>PROVISIONING_PROFILE_REQUIRED</key>
<string>YES</string>


to this


<key>PROVISIONING_PROFILE_ALLOWED</key>
<string>NO</string>
<key>PROVISIONING_PROFILE_REQUIRED</key>
<string>NO</string>


Launch Xcode and then create new project using my Xcode Template for pwned device "View-Based Application" to build and go to either Project Settings 2.0 or Project Settings 2.1 or iPhone Simulator and you don't need the trick to reset it anymore.

Remember, you still need a fake codesign identity and patched MobileInstallation binary in your iPhone.

If you are registered iPhone Developer with provisioning profile and codesign cert from Apple, please remember to revert the PhoneOS.platform Info.plist back to the original one before building your project to App Store.

Updated Notes
If you have "security policy error" after Build & Go. Do these steps

(1) Install a new free app from App Store in iPhone (not sync from iTunes)
(2) Launch that newly purchased free app and then close it.
(3) Reboot your iPhone (that is power off and on again)
(4) Launch the app again that you have Build & Go in Xcode to iPhone.

Please also refer to the latest article for SDK2.2.1
http://iphonesdkdev.blogspot.com/2009/01/how-to-skip-provisioning-profile-for.html




Sunday, September 14, 2008

Copy iPhone SDK headers from Mac to iPhone

Use this shell script in Mac Terminal to copy the installed SDK header files (firmware 2.1) to iPhone , if you have installed the iPhone SDK (build 9M2517) for (2.0 & 2.1 development)
directly and you have to change IPHONEIP for your actual iPhone IP address

copySDKHeaders2.sh : Select all

#!/bin/sh
IPHONEIP=10.0.2.2
#SDKVER=2.0
#SDKVER=2.1
SDKVER=2.2
sdkroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk/System/Library/Frameworks
sdkframeworks[1]=$sdkroot/AddressBook.framework/Headers/*
sdkframeworks[2]=$sdkroot/AddressBookUI.framework/Headers/*
sdkframeworks[3]=$sdkroot/AudioToolbox.framework/Headers/*
sdkframeworks[4]=$sdkroot/AudioUnit.framework/Headers/*
sdkframeworks[5]=$sdkroot/CFNetwork.framework/Headers/*
sdkframeworks[6]=$sdkroot/CoreAudio.framework/Headers/*
sdkframeworks[7]=$sdkroot/CoreFoundation.framework/Headers/*
sdkframeworks[8]=$sdkroot/CoreGraphics.framework/Headers/*
sdkframeworks[9]=$sdkroot/CoreLocation.framework/Headers/*
sdkframeworks[10]=$sdkroot/Foundation.framework/Headers/*
sdkframeworks[11]=$sdkroot/MediaPlayer.framework/Headers/*
sdkframeworks[12]=$sdkroot/OpenAL.framework/Headers/*
sdkframeworks[13]=$sdkroot/OpenGLES.framework/Headers/*
sdkframeworks[14]=$sdkroot/QuartzCore.framework/Headers/*
sdkframeworks[15]=$sdkroot/Security.framework/Headers/*
sdkframeworks[16]=$sdkroot/SystemConfiguration.framework/Headers/*
sdkframeworks[17]=$sdkroot/UIKit.framework/Headers/*
sdkframeworks[18]=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDKVER}.sdk/System/Library/Frameworks/IOKit.framework/Headers/*
iphonesdkroot=/var/sdk
iphoneframeworksroot=$iphonesdkroot/include
iphoneframeworks[1]=$iphoneframeworksroot/AddressBook/
iphoneframeworks[2]=$iphoneframeworksroot/AddressBookUI/
iphoneframeworks[3]=$iphoneframeworksroot/AudioToolbox/
iphoneframeworks[4]=$iphoneframeworksroot/AudioUnit/
iphoneframeworks[5]=$iphoneframeworksroot/CFNetwork/
iphoneframeworks[6]=$iphoneframeworksroot/CoreAudio/
iphoneframeworks[7]=$iphoneframeworksroot/CoreFoundation/
iphoneframeworks[8]=$iphoneframeworksroot/CoreGraphics/
iphoneframeworks[9]=$iphoneframeworksroot/CoreLocation/
iphoneframeworks[10]=$iphoneframeworksroot/Foundation/
iphoneframeworks[11]=$iphoneframeworksroot/MediaPlayer/
iphoneframeworks[12]=$iphoneframeworksroot/OpenAL/
iphoneframeworks[13]=$iphoneframeworksroot/OpenGLES/
iphoneframeworks[14]=$iphoneframeworksroot/QuartzCore/
iphoneframeworks[15]=$iphoneframeworksroot/Security/
iphoneframeworks[16]=$iphoneframeworksroot/SystemConfiguration/
iphoneframeworks[17]=$iphoneframeworksroot/UIKit/
iphoneframeworks[18]=$iphoneframeworksroot/IOKit/

ssh root@$IPHONEIP "mkdir -p $iphoneframeworksroot"
scp -r /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk/usr/include root@$IPHONEIP:$iphonesdkroot
scp -r /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk/usr/lib root@$IPHONEIP:$iphonesdkroot

for index in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
do
echo "copying ${sdkframeworks[index]} to ${iphoneframeworks[index]}"
ssh root@$IPHONEIP "mkdir -p ${iphoneframeworks[index]}"
scp -r ${sdkframeworks[index]} root@$IPHONEIP:${iphoneframeworks[index]}
done


This is for SDK 3.0 header files to iPhone

copySDKHeaders3.sh : Select all

#!/bin/sh
IPHONEIP=10.0.2.2
SDKVER=3.0
sdkroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk/System/Library/Frameworks
sdkframeworks[1]=$sdkroot/AVFoundation.framework/Headers/*
sdkframeworks[2]=$sdkroot/AddressBook.framework/Headers/*
sdkframeworks[3]=$sdkroot/AddressBookUI.framework/Headers/*
sdkframeworks[4]=$sdkroot/AudioToolbox.framework/Headers/*
sdkframeworks[5]=$sdkroot/AudioUnit.framework/Headers/*
sdkframeworks[6]=$sdkroot/CFNetwork.framework/Headers/*
sdkframeworks[7]=$sdkroot/CoreAudio.framework/Headers/*
sdkframeworks[8]=$sdkroot/CoreData.framework/Headers/*
sdkframeworks[9]=$sdkroot/CoreFoundation.framework/Headers/*
sdkframeworks[10]=$sdkroot/CoreGraphics.framework/Headers/*
sdkframeworks[11]=$sdkroot/CoreLocation.framework/Headers/*
sdkframeworks[12]=$sdkroot/ExternalAccessory.framework/Headers/*
sdkframeworks[13]=$sdkroot/Foundation.framework/Headers/*
sdkframeworks[14]=$sdkroot/GameKit.framework/Headers/*
sdkframeworks[15]=$sdkroot/MapKit.framework/Headers/*
sdkframeworks[16]=$sdkroot/MediaPlayer.framework/Headers/*
sdkframeworks[17]=$sdkroot/MessageUI.framework/Headers/*
sdkframeworks[18]=$sdkroot/MobileCoreServices.framework/Headers/*
sdkframeworks[19]=$sdkroot/OpenAL.framework/Headers/*
sdkframeworks[20]=$sdkroot/OpenGLES.framework/Headers/*
sdkframeworks[21]=$sdkroot/QuartzCore.framework/Headers/*
sdkframeworks[22]=$sdkroot/Security.framework/Headers/*
sdkframeworks[23]=$sdkroot/StoreKit.framework/Headers/*
sdkframeworks[24]=$sdkroot/SystemConfiguration.framework/Headers/*
sdkframeworks[25]=$sdkroot/UIKit.framework/Headers/*
sdkframeworks[26]=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDKVER}.sdk/System/Library/Frameworks/IOKit.framework/Headers/*
iphonesdkroot=/var/sdk
iphoneframeworksroot=$iphonesdkroot/include
iphoneframeworks[1]=$iphoneframeworksroot/AVFoundation/
iphoneframeworks[2]=$iphoneframeworksroot/AddressBook/
iphoneframeworks[3]=$iphoneframeworksroot/AddressBookUI/
iphoneframeworks[4]=$iphoneframeworksroot/AudioToolbox/
iphoneframeworks[5]=$iphoneframeworksroot/AudioUnit/
iphoneframeworks[6]=$iphoneframeworksroot/CFNetwork/
iphoneframeworks[7]=$iphoneframeworksroot/CoreAudio/
iphoneframeworks[8]=$iphoneframeworksroot/CoreData/
iphoneframeworks[9]=$iphoneframeworksroot/CoreFoundation/
iphoneframeworks[10]=$iphoneframeworksroot/CoreGraphics/
iphoneframeworks[11]=$iphoneframeworksroot/CoreLocation/
iphoneframeworks[12]=$iphoneframeworksroot/ExternalAccessory/
iphoneframeworks[13]=$iphoneframeworksroot/Foundation/
iphoneframeworks[14]=$iphoneframeworksroot/GameKit/
iphoneframeworks[15]=$iphoneframeworksroot/MapKit/
iphoneframeworks[16]=$iphoneframeworksroot/MediaPlayer/
iphoneframeworks[17]=$iphoneframeworksroot/MessageUI/
iphoneframeworks[18]=$iphoneframeworksroot/MobileCoreServices/
iphoneframeworks[19]=$iphoneframeworksroot/OpenAL/
iphoneframeworks[20]=$iphoneframeworksroot/OpenGLES/
iphoneframeworks[21]=$iphoneframeworksroot/QuartzCore/
iphoneframeworks[22]=$iphoneframeworksroot/Security/
iphoneframeworks[23]=$iphoneframeworksroot/StoreKit/
iphoneframeworks[24]=$iphoneframeworksroot/SystemConfiguration/
iphoneframeworks[25]=$iphoneframeworksroot/UIKit/
iphoneframeworks[26]=$iphoneframeworksroot/IOKit/

ssh root@$IPHONEIP "mkdir -p $iphoneframeworksroot"
scp -r /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk/usr/include root@$IPHONEIP:$iphonesdkroot
scp -r /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk/usr/lib root@$IPHONEIP:$iphonesdkroot

for index in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
do
echo "copying ${sdkframeworks[index]} to ${iphoneframeworks[index]}"
ssh root@$IPHONEIP "mkdir -p ${iphoneframeworks[index]}"
scp -r ${sdkframeworks[index]} root@$IPHONEIP:${iphoneframeworks[index]}
done

.
.
.

Wednesday, September 10, 2008

XCode Template for pwned iPhone 2.0.x

This is how to skip the Provisioning Profile in order to build & go in official sdk applications (not using toolchain headers) when you are not registered iPhone developer (US$99 program).

Here is how

(1) If you have an existing project from the Official Template, you need to change the code-sign identity and add two user-defined
settings in your Project Setting as below



Info.plist:Select all

"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Pwned Developer";
PROVISIONING_PROFILE_ALLOWED = NO;
PROVISIONING_PROFILE_REQUIRED = NO;


There are two instances for this part to change (one for Debug and another for Release)

(2)
Then amend the Info.plist of your project
and add these
Info.plist:Select all

<key>SignerIdentity</key>
<string>Apple iPhone OS Application Signing</string>


Then you can build & go your project with support of debug and setting break point like other registered iPhone developer

To use this method to build & go. You need
(1) Have a fake code sign identity called "iPhone Pwned Developer" in your Mac (if you have not already done so)

Here is the nice guide from Apple to create a self-signed identity
http://developer.apple.com/documentation/Security/Conceptual/CodeSigningGuide/Procedures/chapter_3_section_2.html

updated link
http://developer.apple.com/documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html#//apple_ref/doc/uid/TP40005929-CH4-SW1

(2) You need to patch the MobileInstallation in your iPhone (if you have not already done so)
Here is how to patch the binary in iPhone and create backup first of course (the patch program is for iPhone which I compile from the source and supports 2.0 to 2.0.2)

Shellscript:Select all

wget http://www.cocoatouchdev.com/javacom/mobileinstallation_patch
cp -p /System/Library/PrivateFrameworks/MobileInstallation.framework/MobileInstallation /System/Library/PrivateFrameworks/MobileInstallation.framework/MobileInstallation.backup
chmod +x mobileinstallation_patch
./mobileinstallation_patch
ldid -s /System/Library/PrivateFrameworks/MobileInstallation.framework/MobileInstallation


The updated MobileInstallation patch, please use my package as posted here
http://hackint0sh.org/forum/showpost.php?p=340693&postcount=14

(3) You don't need to patch SpringBoard, as the changing of Info.plist has done this trick.


I have updated my XCode Template to 3.5.2

Please refer to this post for the instructions
http://iphonesdkdev.blogspot.com/2008/09/xcode-template-for-pwned-iphone-device.html


To use the "Open Tool Chain" template you need to install the open toolchain headers, run this shell script in your Mac

$ sudo mkdir -p /Developer/SDKs/iPhoneOS.sdk/Versions/iPhoneOS2.0.sdk/
$ svn co http://iphone-dev.googlecode.com/svn/branches/include-1.2-sdk
$ cd include-1.2-sdk
$ ./configure --prefix=/Developer/SDKs/iPhoneOS.sdk/Versions/iPhoneOS2.0.sdk/
$ sudo sh install-headers.sh


To test the new template "View-Based Application"
Create a new project from "View-Based Application" of "Application Pwned" and modified the ViewController file and implement the loadView as below, then Build & Go to your device.

You need to have the "iPhone Pwned Developer" certifcate in your Mac plus patch of MobileInstallation in your iPhone for successful build & go

ViewController.m:Select all

- (void)loadView {
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view = contentView;
[contentView release];
self.view.autoresizesSubviews = YES;
CGRect frame = CGRectMake(10.0, 10.0, 250.0, 100.0);

UITextView *textView = [[[UITextView alloc] initWithFrame:frame] autorelease];

textView.textColor = [UIColor blackColor];
textView.font = [UIFont fontWithName:@"Arial" size:18.0];
textView.backgroundColor = [UIColor whiteColor];

textView.text = @"This is the time for Developer to port all applications to firmware 2.0";

[self.view addSubview: textView];

}



Important Note
The template will fail to build & go when you change your build to iPhone Simulator and then switch it back to build & go to the iPhone device.

The error message is

CodeSign error: no provisioning profiles found for code signing identity 'iPhone Pwned Developer'


If this happens, the temporary solution is to

(1) Close the project file in Xcode
(2) Use Mac terminal to change directory to the project directory and remove the temp file in project file (e.g. if the Project is called HelloWorld)

cd HelloWorld
rm HelloWorld.xcodeproj/*.pbxuser

(4) Then open the xcode project file and build and go to device again.

For Firmware 2.1 & iPhone SDK (build 9M2517) for (2.0 & 2.1 development), please search this blog for updated trick

[How-to] Install gcc compiler and build toolchain app for pwned iPhone 2.0.x firmware

The gcc in iPhone procedure is updated here for the pwned iPhone firmware 2.0/2.0.1/2.0.2

If you install iPhone GCC, it is important to set root partition to about 700M in pwnage, if you set it too small your will get into trouble whenever there is an upgrade of GCC, as some of the libexec cannot be symlink to second partition.

You have to install the following packages in Cydia
  • GNU C Compiler 
  • iPhone 2.0 Toolchain 
  • Make 
  • Link Indentity Editor
  • wget (... in order to download the following sample in iPhone)
  • zip (... in order to unzip the following sample in iPhone)

then download the following zip file in your iPhone to test build your iPhone toolchain app

shellscript: Select all

wget http://www.iphone.org.hk/attach/38270-HelloWorld2.zip
unzip 38270-HelloWorld2.zip



shellscript: Select all

cd HelloWorld
make
make install


Restart your springboard, then you will have the HelloWorld app on your springboard

To uninstall HelloWorld.app
shellscript: Select all

cd HelloWorld
make uninstall

Stop The Device from Sleeping Programmatically

Select all

[[ UIApplication sharedApplication ] setIdleTimerDisabled: YES ];

Add Organization name to Xcode Project

shellscript: Select all

defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions ' { "ORGANIZATIONNAME" = "javacom"; } '

Wednesday, August 27, 2008

How-To copy SDK headers to iPhone and compile SDK applications in iPhone

Pre-requisites:
(1) jailbreak iPhone with pwned firmware 2.0.x
(2) Install the following packages in Cydia Installer

  • GNU C Compiler

  • iPhone 2.0 Toolchain

  • Make

  • Link Indentity Editor

  • wget (... in order to download the following sample in iPhone)

  • zip (... in order to unzip the following sample in iPhone)



Here is the procedure on how to copy the iPhone SDK headers from your mac to iPhone GCC to have a SDK development environment in iPhone

I have installed the sdk header files to /var/sdk of iPhone

If you use Linux / Microsoft Windows, see this on how to get the header files from the SDK
http://www.theiphonewiki.com/wiki/index.php?title=Toolchain_2.0

Use this shell script in Mac Terminal to copy the installed SDK header files to iPhone directly
and you have to change IPHONEIP for your actual iPhone IP address

copySDKHeaders.sh : Select all

#!/bin/sh
IPHONEIP=10.0.2.2
sdkroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/System/Library/Frameworks
sdkframeworks[1]=$sdkroot/AddressBook.framework/Headers/*
sdkframeworks[2]=$sdkroot/AddressBookUI.framework/Headers/*
sdkframeworks[3]=$sdkroot/AudioToolbox.framework/Headers/*
sdkframeworks[4]=$sdkroot/AudioUnit.framework/Headers/*
sdkframeworks[5]=$sdkroot/CFNetwork.framework/Headers/*
sdkframeworks[6]=$sdkroot/CoreAudio.framework/Headers/*
sdkframeworks[7]=$sdkroot/CoreFoundation.framework/Headers/*
sdkframeworks[8]=$sdkroot/CoreGraphics.framework/Headers/*
sdkframeworks[9]=$sdkroot/CoreLocation.framework/Headers/*
sdkframeworks[10]=$sdkroot/Foundation.framework/Headers/*
sdkframeworks[11]=$sdkroot/MediaPlayer.framework/Headers/*
sdkframeworks[12]=$sdkroot/OpenAL.framework/Headers/*
sdkframeworks[13]=$sdkroot/OpenGLES.framework/Headers/*
sdkframeworks[14]=$sdkroot/QuartzCore.framework/Headers/*
sdkframeworks[15]=$sdkroot/Security.framework/Headers/*
sdkframeworks[16]=$sdkroot/SystemConfiguration.framework/Headers/*
sdkframeworks[17]=$sdkroot/UIKit.framework/Headers/*
sdkframeworks[18]=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.0.sdk/System/Library/Frameworks/IOKit.framework/Headers/*
iphonesdkroot=/var/sdk
iphoneframeworksroot=$iphonesdkroot/include
iphoneframeworks[1]=$iphoneframeworksroot/AddressBook/
iphoneframeworks[2]=$iphoneframeworksroot/AddressBookUI/
iphoneframeworks[3]=$iphoneframeworksroot/AudioToolbox/
iphoneframeworks[4]=$iphoneframeworksroot/AudioUnit/
iphoneframeworks[5]=$iphoneframeworksroot/CFNetwork/
iphoneframeworks[6]=$iphoneframeworksroot/CoreAudio/
iphoneframeworks[7]=$iphoneframeworksroot/CoreFoundation/
iphoneframeworks[8]=$iphoneframeworksroot/CoreGraphics/
iphoneframeworks[9]=$iphoneframeworksroot/CoreLocation/
iphoneframeworks[10]=$iphoneframeworksroot/Foundation/
iphoneframeworks[11]=$iphoneframeworksroot/MediaPlayer/
iphoneframeworks[12]=$iphoneframeworksroot/OpenAL/
iphoneframeworks[13]=$iphoneframeworksroot/OpenGLES/
iphoneframeworks[14]=$iphoneframeworksroot/QuartzCore/
iphoneframeworks[15]=$iphoneframeworksroot/Security/
iphoneframeworks[16]=$iphoneframeworksroot/SystemConfiguration/
iphoneframeworks[17]=$iphoneframeworksroot/UIKit/
iphoneframeworks[18]=$iphoneframeworksroot/IOKit/

ssh root@$IPHONEIP "mkdir -p $iphoneframeworksroot"
scp -r /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr/include root@$IPHONEIP:$iphonesdkroot
scp -r /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr/lib root@$IPHONEIP:$iphonesdkroot

for index in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
do
echo "copying ${sdkframeworks[index]} to ${iphoneframeworks[index]}"
ssh root@$IPHONEIP "mkdir -p ${iphoneframeworks[index]}"
scp -r ${sdkframeworks[index]} root@$IPHONEIP:${iphoneframeworks[index]}
done


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)
Select all

ssh-keygen -t rsa


(b) create .ssh directory in iPhone (assume ip address of iPhone is 10.0.2.2)
Select all

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
Select all
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
Select all

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


to

Select all

StrictModes no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys


(e)reboot iPhone

I have successfully compiled a modified SDK sample app UICategory (non-Interface Builder verison)

Here is the project folder to test your installation.

(i) copy it (using wget) and unzip it in iPhone
Select all

wget http://www.iphone.org.hk/attach/39773-UICatalog.zip
unzip 39773-UICatalog.zip


(ii) then run
Select all

cd UICatalog
make
make install


to build and install the project in iPhone

Friday, August 15, 2008

How To force Orientation to Landscape in iPhone

This is how to force Orientation to Landscape in iPhone.


AppDelegate.m : Select all

application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;


Info.plist : Select all

<key>UIStatusBarOrientation</key>
<string>UIInterfaceOrientationLandscapeRight</string>

Tuesday, July 8, 2008

[How-to] print NSString to stdout

This is how to print the NSString to stdout so that it can display in debug console window of Xcode.


main.m : Select all

#import <Foundation/Foundation.h>

void NSPrint (NSString *str)
{
[str writeToFile:@"/dev/stdout" atomically:NO encoding:NSUTF8StringEncoding error:nil];
}

void NSPrintUTF8 (NSString *str)
{
printf("%s", [str cStringUsingEncoding:NSUTF8StringEncoding]);
}

void NSPrintMac (NSString *str)
{
printf("%s", [str cStringUsingEncoding:NSMacOSRomanStringEncoding]);
}

#if defined(TARGET_IPHONE_SIMULATOR)
#define LogMethod() printf("%s\n", [[NSString stringWithFormat:@"Simulator-[%@ %s]", self, _cmd] cStringUsingEncoding:NSUTF8StringEncoding]);
#else
#define LogMethod() NSLog(@"-[%@ %s]", self, _cmd])
#endif


int main(int argc, char *argv[]) {
NSPrint(@"Hello, World\n");
NSPrintMac(@"Hello, Mac Encoding World\n");
LogMethod();
}


This is how to print out the NSString and append to a text file.


appendtxt.m : Select all

NSFileHandle *aFileHandle = [NSFileHandle fileHandleForWritingAtPath:[@"/tmp/myapp.log" stringByExpandingTildeInPath]];
[aFileHandle truncateFileAtOffset:[aFileHandle seekToEndOfFile]];
[aFileHandle writeData:[[NSString stringWithFormat:@"Simulator-[%@ %s]", self, _cmd] dataUsingEncoding:NSUTF8StringEncoding]];
[aFileHandle writeData:[NSStringFromCGSize(contentSize) dataUsingEncoding:NSUTF8StringEncoding]];





Saturday, June 28, 2008

[How-To] Install gcc compiler in iPhone (1.1.x firmware)

Cydia is a new package management replacement to the existing Installer.app. And it now also brings the gcc compiler to iPhone in firmware 1.1.x

Although it is slow to compile in iPhone but it is stable and very native.

You can follow these steps to install the compiler and related headers and utilities:

1. Set your iPhone Auto-Lock to "Never"
2. Goto Installer and install the package called "Cydia Installer" (version 1.0). It will take some time to download and install, so you should have connected your iPhone to Wifi
3. After installation of Cydia, iPhone will reboot and you will find a new icon "Cydia" in your Home Screen. Start "Cydia" and it will tell you to update Critical Packages. Follow the instructions to "Update All"
4. After update of Critical Packages in Cydia, install the following 3 packages

GNU C Compiler
Make
iPhone 1.1.1 Headers

5. Then you can have gcc compiler in your iPhone now. You can use Mac Terminal or putty to access the terminal of iPhone and start building your application.

Please take note that after the installation of Cydia, your BSD subsystem is now changed to Fake BSD subsystem and also fixed a number of bugs. So don't update BSD subsystem from the Installer.app

You may want to try some HelloWorld example, and here is the project that you can try

copy and unzip it to your iPhone
then

cd HelloWorld
make install
./restart


Then you will have a new program HelloWorld.

To uninstall this HelloWorld

make uninstall



Enjoy!

Friday, June 27, 2008

Unoffical iPhone SDK (building iPhone OS2.0 app without using iPhone SDK)

It is possible to build iPhone OS 2.0 native application using open toolchain header and without using official iPhone SDK nor without Mac OS
Read this article
Upgrading the iPhone Toolchain


Hide Status Bar

This is how to hide the status bar in iPhone. For the Open toolchain api is available. However, for Official SDK API, edit the Info.plist is necessary.


Official iPhone OS 2.0 SDK headers version


Info.plist : Select all

<key>UIStatusBarHidden</key>
<true />

or. programmatically,

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];


Open Tool Chain headers version


Hello.app : Select all


[UIHardware _setStatusBarHeight:0.0f];
[self setStatusBarMode:2 duration:0.0f];
[self setStatusBarHidden:YES animated:NO]; // hide status bar

Xcode Tips

1. Read the Xcode Workspace Guide, it is available after launching Xcode. It is under Help -> Xcode Workspace Guide

2. Make full use of Snapshots to keep different versions of the project. It is under File -> Make Snapshot

3. Make full use of code completion. It is under Xcode Preferences > Code Sense > Code Completion > Automatically Suggest _> immediate
Press esc key for auto suggestion

4. There are two ways to search for API reference from the Xcode text editor:
Option–double-click a symbol name
Select an expression and choose Help > Find Selected Text in API Reference

Command–double-click a symbol name
and goes to the header file (command-shift-w to close the header file)

5. Learn and use Refractor instead of Find & Replace

6. Use Project -> Class Browser

7. Use #pragma in source code to improve readability
#pragma mark PRINTING FUNCTIONS
To add a separator to the Function menu use:
#pragma mark -

8. Short Cut Keys in code editor
indent : Command-]
un-indent : Command-[
block select : Option key while clicking and dragging

9. Use this DEBUGLOG to replace NSLog

#ifdef DEBUGON
#define DEBUGLOG if (DEBUGON) NSLog
#else
#define DEBUGLOG
#endif


In the project settings of Debug add this user-defined setting (under Debug)

GCC_PREPROCESSOR_DEFINITIONS DEBUGON=1



Then, you can simply use DEBUGLOG(@"Testing output %.2f", myFloat); in your code
and in Debug Build NSLog will be used, but in Release Build or Distribution Build, no NSLog output.
.
.
.

Thursday, June 19, 2008

UIAccelerometer Sample Code

It is possible to use Open Tool Chain Header with the SDK and the official iPhone OS 2.0 SDK headers, the following demonstrates these two versions for the Accelerometer


Official iPhone OS 2.0 SDK headers version



SensorSDK3.app main.m : Select all


/
// main.m
// SensorSDK3.app
//
#import <UIKit/UIKit.h>

int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"SensorSDK3AppDelegate");
[pool release];
return retVal;
}


SensorSDK3AppDelegate.h : Select all


//
// SensorSDK3AppDelegate.h
// SensorSDK3.app
//

#import <UIKit/UIKit.h>
#include <stdio.h>
#include <time.h>
#include <math.h>

#define kUpdateFrequency 10 // Hz


@interface SensorSDK3AppDelegate : NSObject {
UIWindow *window;
UITextView *textView;
UIImageView *xarrow;
}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UITextView *textView;
@property (nonatomic, retain) UIImageView *xarrow;

- (void)acceleratedInX:(float)xx Y:(float)yy Z:(float)zz;
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration;
@end

SensorSDK3AppDelegate.m : Select all


//
// SensorSDK3AppDelegate.m
// SensorSDK3.app
//

#import "SensorSDK3AppDelegate.h"

UIImage *createImageWithText(CGSize imageSize, NSString *text);

@implementation SensorSDK3AppDelegate

@synthesize window;
@synthesize textView;
@synthesize xarrow;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];


self.textView = [[UITextView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
self.textView.font = [UIFont systemFontOfSize:24];
self.textView.editable = NO;
self.textView.textAlignment = UITextAlignmentLeft;

UIImage *img = createImageWithText(CGSizeMake(85,40),@"-->");
self.xarrow = [[UIImageView alloc] initWithImage:img];
self.xarrow.center=self.textView.center;
self.xarrow.clearsContextBeforeDrawing = NO;


[textView addSubview:xarrow];

// Show window
[window addSubview:textView];
[window makeKeyAndVisible];

[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(20.0 / kUpdateFrequency)];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];

}

/*
The meaning of X, Y, Z by Erica Sadun (with modification for the range from -1.0 to 1.0 for firmware 2.0)
X = Roll X corresponds to roll, or rotation around the axis that runs from your home button to your earpiece.
Values vary from 1.0 (rolled all the way to the left) to -1.0 (rolled all the way to the right).

Y = Pitch. Place your iPhone on the table and mentally draw a horizontal line about half-way down the screen.
That's the axis around which the Y value rotates.
Values go from 1.0 (the headphone jack straight down) to -1.0 (the headphone jack straight up).

Z = Face up/face down. I expected the Z value to correspond to yaw. And it does not.
It refers to whether your iPhone is face up (-1.0) or face down (1.0).
When placed on it side, either the side with the volume controls and ringer switch, or the side directly opposite
, the Z value equates to 0.0.
*/

- (void)acceleratedInX:(float)xx Y:(float)yy Z:(float)zz
{

// Create Status feedback string
NSString *xstring = [NSString stringWithFormat:
@"X (roll, %4.1f%%): %f\nY (pitch %4.1f%%): %f\nZ (%4.1f%%) : %f",
100.0 - (xx + 1.0) * 100.0, xx,
100.0 - (yy + 1.0) * 100.0, yy,
100.0 - (zz + 1.0) * 100.0, zz
];
self.textView.text = xstring;

// Revert Arrow and then rotate to new coords
float angle = atan2(xx, yy);
angle += M_PI / 2.0;

CGAffineTransform affineTransform = CGAffineTransformIdentity;
affineTransform = CGAffineTransformConcat( affineTransform, CGAffineTransformMakeRotation(angle));
self.xarrow.transform = affineTransform;

}

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
[self acceleratedInX:acceleration.x Y:acceleration.y Z:acceleration.z];
}


- (void)dealloc {
[textView release];
[xarrow release];
[window release];
[super dealloc];
}

@end

// Returns an image of the given size containing the given string
UIImage *createImageWithText(CGSize imageSize, NSString *text) {

// Create a bitmap graphics context of the given size
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, imageSize.width*4, colorSpace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
if (context== NULL) {
return nil;
}

// Custom CGContext coordinate system is flipped with respect to UIView, so transform, then push
CGContextTranslateCTM(context, 0, imageSize.height);
CGContextScaleCTM(context, 1.0, -1.0);
UIGraphicsPushContext(context);

// Inset the text rect then draw the text
CGRect textRect = CGRectMake(4, 2, imageSize.width - 8, imageSize.height - 8);
UIFont *font = [UIFont boldSystemFontOfSize:24];
[[UIColor blackColor] set];
[text drawInRect:textRect withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];

// Create and return the UIImage object
CGImageRef cgImage = CGBitmapContextCreateImage(context);
UIImage *uiImage = [[UIImage alloc] initWithCGImage:cgImage];
UIGraphicsPopContext();
CGContextRelease(context);
CGImageRelease(cgImage);
return uiImage;
}



Open Tool Chain headers version



HelloSensor.app : Select all


/*
HelloSensor.app
main.m
*/
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <UIKit/UIWindow.h>
#import <UIKit/UIHardware.h>
#import <UIKit/UIApplication.h>
#import <UIKit/UIImageView.h>
#import <UIKit/UIImage.h>
#import <UIKit/UITextView.h>
#include <stdio.h>
#include <time.h>
#include <math.h>

#ifdef ASPEN
#ifndef UIKIT_UIFont_UIColor_H
#define UIKIT_UIFont_UIColor_H
typedef float CGFloat;
#import
#import
#endif

#ifndef UIKIT_UIAccelerometer_H
#define UIKIT_UIAccelerometer_H
#import
#define kUpdateFrequency 10 // Hz
#endif

#endif


#ifdef ASPEN
@interface HelloSensor : UIApplication
#else
@interface HelloSensor : UIApplication
#endif
{
UIWindow *window;
UIView *mainView;
UITextView *textView;
UIImageView *xarrow;
}
#ifdef ASPEN
- (void)acceleratedInX:(float)xx Y:(float)yy Z:(float)zz;
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration;
#endif
@end

@implementation HelloSensor


#ifdef ASPEN
// UIAccelerometer delegate method in SDK
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
[self acceleratedInX:acceleration.x Y:acceleration.y Z:acceleration.z];
}
#endif

/*
The meaning of X, Y, Z by Erica Sadun
X = Roll X corresponds to roll, or rotation around the axis that runs from your home button to your earpiece.
Values vary from 0.5 (rolled all the way to the left) to -0.5 (rolled all the way to the right).

Y = Pitch. Place your iPhone on the table and mentally draw a horizontal line about half-way down the screen.
That's the axis around which the Y value rotates.
Values go from 0.5 (the headphone jack straight down) to -0.5 (the headphone jack straight up).

Z = Face up/face down. I expected the Z value to correspond to yaw. And it does not.
It refers to whether your iPhone is face up (-0.5) or face down (0.5).
When placed on it side, either the side with the volume controls and ringer switch, or the side directly opposite
, the Z value equates to 0.0.
*/

- (void)acceleratedInX:(float)xx Y:(float)yy Z:(float)zz
{
// Create Status feedback string
NSString *xstring = [NSString stringWithFormat:
@"X (roll, %4.1f%%): %f\nY (pitch %4.1f%%): %f\nZ (%4.1f%%) : %f",
100.0 - (xx + 0.5) * 100.0, xx,
100.0 - (yy + 0.5) * 100.0, yy,
100.0 - (zz + 0.5) * 100.0, zz];
[textView setText:xstring];

// Revert Arrow and then rotate to new coords
[xarrow setTransform:CGAffineTransformIdentity];
float angle = atan2(yy, xx);
angle *= 180.0/3.14159;
[xarrow setRotationBy:angle];
}


- (void) applicationDidFinishLaunching: (id) unused
{
#ifdef ASPEN
[UIHardware _setStatusBarHeight:0.0f];
[self setStatusBarMode:2 duration:0.0f];
[self setStatusBarHidden:YES animated:NO]; // hide status bar
#endif

struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
rect.origin.x = rect.origin.y = 0.0f;
window = [[UIWindow alloc] initWithContentRect: rect];
mainView = [[UIView alloc] initWithFrame: rect];

textView = [[UITextView alloc] initWithFrame:
CGRectMake(0.0, 0.0, 320.0, 480.0)];
[textView setEditable:NO];
#ifdef ASPEN
[textView setFont:[UIFont systemFontOfSize:24]];
#else
[textView setTextSize:24];
#endif
[mainView addSubview: textView];

// I changed the arrow by getting it from Notes app
xarrow = [[UIImageView alloc] initWithFrame: CGRectMake(135.0, 320.0, 50.0, 46.0)];
UIImage *img = [[UIImage imageAtPath:@"/Applications/MobileNotes.app/arrow right.png"] retain];

// If you want the original arrow get it from http://www.tuaw.com/2007/09/10/iphone-coding-using-the-accelerometer/
// xarrow = [[UIImageView alloc] initWithFrame: CGRectMake(50.0, 320.0, 200.0, 50.0)];
// [[UIImage imageAtPath:[[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png" inDirectory:@"/"]] retain];


[xarrow setImage:img];
[textView addSubview:xarrow];

[window orderFront: self];
[window setContentView: mainView];

#ifdef ASPEN
[window makeKeyAndVisible];
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kUpdateFrequency)];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
#else
[window makeKey: self];
[window _setHidden: NO];
#endif

}
@end

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

Wednesday, June 18, 2008

First iPhone SDK Application

It is possible to use Open Tool Chain Header with the SDK and the official iPhone OS 2.0 SDK headers, the following demonstrates these two versions


Official iPhone OS 2.0 SDK headers version


HelloSDK.app : Select all


/*
main.m
HelloSDK
*/
#import <UIKit/UIKit.h>
@interface MyView : UIView {
}
@end
@implementation MyView
- (void)drawRect:(CGRect)rect {
[[UIColor whiteColor] set];
[@"Hello SDK" drawInRect:CGRectMake(0, 100, 320, 50)
withFont:[UIFont fontWithName:@"Marker Felt" size:50]
lineBreakMode:UILineBreakModeMiddleTruncation
alignment:UITextAlignmentCenter];
}
@end

@interface HelloSDK2AppDelegate : NSObject {
UIWindow *window;
MyView *contentView;
}
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) MyView *contentView;
@end

@implementation HelloSDK2AppDelegate
@synthesize window;
@synthesize contentView;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Create window
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

// Set up content view
self.contentView = [[[MyView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
[window addSubview:contentView];

// Show window
[window makeKeyAndVisible];
}

- (void)dealloc {
[contentView release];
[window release];
[super dealloc];
}
@end

int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"HelloSDK2AppDelegate");
[pool release];
return retVal;
}

Open Tool Chain headers version


HelloToolChain.app : Select all


/*
HelloToolChain.app
main.m
*/

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

// include for the sdk compiler and open toolchain headers
#ifndef UIKIT_UIFont_UIColor_H
#define UIKIT_UIFont_UIColor_H
typedef float CGFloat;
#import <UIKit/UIFont.h>
#import <UIKit/UIColor.h>
#endif

@interface HelloToolChain : UIApplication
{
}
@end

@implementation HelloToolChain
- (void) applicationDidFinishLaunching: (NSNotification *)aNotification
{
UIWindow *window = [[UIWindow alloc] initWithContentRect: [UIHardware fullScreenApplicationContentRect]];
UITextLabel *label = [[UITextLabel alloc] initWithFrame: CGRectMake(0, 100, 320, 50)];
[label setFont:[UIFont fontWithName:@"Marker Felt" size:50]];
[label setCentersHorizontally: YES];
[label setText:@"Hello ToolChain"];
[label setBackgroundColor:[UIColor blackColor]];
[label setColor:[UIColor whiteColor]];
UIView *mainView = [[UIView alloc] initWithFrame: [UIHardware fullScreenApplicationContentRect]];
[mainView addSubview: label];
[mainView becomeFirstResponder];
[window orderFront: self];
[window makeKeyAndVisible];
[window setContentView: mainView];
}
@end

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

Sunday, June 8, 2008

SDKs for iPhone

Open Toolchain


Open Toolchain [1] is for the development of 1.x native application for iPhone, It can be used in Mac OS X (Intel/PPC) 10.4/10.5, Linux, Cygwin or MinGW. This SDK uses gcc cross compiler for the development.


Build from sources method:

There are also Pre-build Binary for different Operating System (OS) and CPU


  1. WinChain (Only for Windows XP)  WinChain Download from this ftp site

  2. Binary ToolChain Installer (Only for Mac OS X 10.4 Tiger and Intel CPU)    Download from here

  3. iPhone Toolchain VMWare Debian Linux Image [use for VMWare Player / VMWare Workstation (win) / VMWare Fusion (Mac)]   VMWare Debian Linux Image Download from this ftp site


There were some changes in 1.1.2/3 API, toolchain header files should also be updated




iPhone SDK


iPhone SDK is the offical development tools from Apple Inc for iPhone Developer to develop firmware 2.0 Native Application. It is only available for Mac OS X 10.5.2 and Intel CPU (see ppc hack here).


The latest iPhone SDK beta 8 can be downloaded from Apple iPhone Developer Website,
Previous version of iPhone SDK can be downloaded from this ftp site. After installation of the iPhone SDK, all the sample codes of that version of SDK can be obtained from harddisk. They are in


/Developer/Platforms/iPhoneOS.platform/Developer/Documentation/DocSets/com.apple.adc.documentation.AppleiPhone2_0.iPhoneLibrary.docset/Contents/Resources/Documents/samplecode


There are numerous limitations [2] for iPhone SDK in development of official iPhone software, Therefore iPhone Dev Team provides a how-to use iPhone SDK with Open Toolchain API


It is now also possible to build firmware 2.0 app without using the official sdk and Mac OS. Read this article - Upgrading the iPhone Toolchain


Apple Inc has also provided iPhone Web Application documentation, but it is less attractive than Native Application.




Xcode Template


To build iPhone Native Application for 2.0, you can
  1. Join the Apple iPhone Developer $99 program and follows the offical SDK API

  2. Install the Open toolchain headers and the Xcode Template as per instructions here