Wednesday, January 21, 2009

Source Code : Get Hardware Info of iPhone

This is a collection of open source codes to print out the hardware info of iPhone. If you know more, please post link here in comment and I will update it.

Battery Info source (requires IOKit header files from SimulatorSDK)
http://forums.macrumors.com/showthread.php?t=474628

Memory & CPU
http://furbo.org/2007/08/21/what-the-iphone-specs-dont-tell-you/

Process
Landon Fuller, iphonesdk@googlegroups.com

hwinfo.c Select all

#import <stdio.h>
#import <string.h>

#import <mach/mach_host.h>
#import <sys/sysctl.h>

#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/ps/IOPowerSources.h>
#include <IOKit/ps/IOPSKeys.h>

#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>

void printMemoryInfo()
{
size_t length;
int mib[6];
int result;

printf("Memory Info\n");
printf("-----------\n");

int pagesize;
mib[0] = CTL_HW;
mib[1] = HW_PAGESIZE;
length = sizeof(pagesize);
if (sysctl(mib, 2, &pagesize, &length, NULL, 0) < 0)
{
perror("getting page size");
}
printf("Page size = %d bytes\n", pagesize);
printf("\n");

mach_msg_type_number_t count = HOST_VM_INFO_COUNT;

vm_statistics_data_t vmstat;
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count) != KERN_SUCCESS)
{
printf("Failed to get VM statistics.");
}

double total = vmstat.wire_count + vmstat.active_count + vmstat.inactive_count + vmstat.free_count;
double wired = vmstat.wire_count / total;
double active = vmstat.active_count / total;
double inactive = vmstat.inactive_count / total;
double free = vmstat.free_count / total;

printf("Total = %8d pages\n", vmstat.wire_count + vmstat.active_count + vmstat.inactive_count + vmstat.free_count);
printf("\n");
printf("Wired = %8d bytes\n", vmstat.wire_count * pagesize);
printf("Active = %8d bytes\n", vmstat.active_count * pagesize);
printf("Inactive = %8d bytes\n", vmstat.inactive_count * pagesize);
printf("Free = %8d bytes\n", vmstat.free_count * pagesize);
printf("\n");
printf("Total = %8d bytes\n", (vmstat.wire_count + vmstat.active_count + vmstat.inactive_count + vmstat.free_count) * pagesize);
printf("\n");
printf("Wired = %0.2f %%\n", wired * 100.0);
printf("Active = %0.2f %%\n", active * 100.0);
printf("Inactive = %0.2f %%\n", inactive * 100.0);
printf("Free = %0.2f %%\n", free * 100.0);
printf("\n");

mib[0] = CTL_HW;
mib[1] = HW_PHYSMEM;
length = sizeof(result);
if (sysctl(mib, 2, &result, &length, NULL, 0) < 0)
{
perror("getting physical memory");
}
printf("Physical memory = %8d bytes\n", result);
mib[0] = CTL_HW;
mib[1] = HW_USERMEM;
length = sizeof(result);
if (sysctl(mib, 2, &result, &length, NULL, 0) < 0)
{
perror("getting user memory");
}
printf("User memory = %8d bytes\n", result);
printf("\n");
}

void printProcessorInfo()
{
size_t length;
int mib[6];
int result;

printf("Processor Info\n");
printf("--------------\n");

mib[0] = CTL_HW;
mib[1] = HW_CPU_FREQ;
length = sizeof(result);
if (sysctl(mib, 2, &result, &length, NULL, 0) < 0)
{
perror("getting cpu frequency");
}
printf("CPU Frequency = %d hz\n", result);

mib[0] = CTL_HW;
mib[1] = HW_BUS_FREQ;
length = sizeof(result);
if (sysctl(mib, 2, &result, &length, NULL, 0) < 0)
{
perror("getting bus frequency");
}
printf("Bus Frequency = %d hz\n", result);
printf("\n");
}

int printBatteryInfo()
{
CFTypeRef blob = IOPSCopyPowerSourcesInfo();
CFArrayRef sources = IOPSCopyPowerSourcesList(blob);

CFDictionaryRef pSource = NULL;
const void *psValue;

int numOfSources = CFArrayGetCount(sources);
if (numOfSources == 0) {
perror("Error getting battery info");
return 1;
}

printf("Battery Info\n");
printf("------------\n");

for (int i = 0 ; i < numOfSources ; i++)
{
pSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sources, i));
if (!pSource) {
perror("Error getting battery info");
return 2;
}
psValue = (CFStringRef)CFDictionaryGetValue(pSource, CFSTR(kIOPSNameKey));

int curCapacity = 0;
int maxCapacity = 0;
int percent;

psValue = CFDictionaryGetValue(pSource, CFSTR(kIOPSCurrentCapacityKey));
CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &curCapacity);

psValue = CFDictionaryGetValue(pSource, CFSTR(kIOPSMaxCapacityKey));
CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &maxCapacity);

percent = (int)((double)curCapacity/(double)maxCapacity * 100);

printf ("powerSource %d of %d: percent: %d/%d = %d%%\n", i+1, CFArrayGetCount(sources), curCapacity, maxCapacity, percent);
printf("\n");

}

}

int printProcessInfo() {
int mib[5];
struct kinfo_proc *procs = NULL, *newprocs;
int i, st, nprocs;
size_t miblen, size;

/* Set up sysctl MIB */
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_ALL;
mib[3] = 0;
miblen = 4;

/* Get initial sizing */
st = sysctl(mib, miblen, NULL, &size, NULL, 0);

/* Repeat until we get them all ... */
do {
/* Room to grow */
size += size / 10;
newprocs = realloc(procs, size);
if (!newprocs) {
if (procs) {
free(procs);
}
perror("Error: realloc failed.");
return (0);
}
procs = newprocs;
st = sysctl(mib, miblen, procs, &size, NULL, 0);
} while (st == -1 && errno == ENOMEM);

if (st != 0) {
perror("Error: sysctl(KERN_PROC) failed.");
return (0);
}

/* Do we match the kernel? */
assert(size % sizeof(struct kinfo_proc) == 0);

nprocs = size / sizeof(struct kinfo_proc);

if (!nprocs) {
perror("Error: printProcessInfo.");
return(0);
}
printf(" PID\tName\n");
printf("-----\t--------------\n");
for (i = nprocs-1; i >=0; i--) {
printf("%5d\t%s\n",(int)procs[i].kp_proc.p_pid, procs[i].kp_proc.p_comm);
}
free(procs);
return (0);
}


int main(int argc, char **argv)
{
printf("iPhone Hardware Info\n");
printf("====================\n");
printf("\n");

printMemoryInfo();
printProcessorInfo();
printBatteryInfo();
printProcessInfo();
return (0);
}


MAC Address & IP address of network interfaces
original source from devforums.apple.com and modified to show IP address and exclude loopback addresses

macaddress.c Select all

#include <stdio.h>
#include <stdlib.h>
#include <ifaddrs.h>
#include <string.h>
#include <stdbool.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <arpa/inet.h>
#include <ifaddrs.h>

#if ! defined(IFT_ETHER)
#define IFT_ETHER 0x6/* Ethernet CSMACD */
#endif

int main(int argc, char **argv)
{
bool success;
struct ifaddrs *addrs;
const struct ifaddrs *cursor;
const struct sockaddr_dl *dlAddr;
const uint8_t *base;
int i;

success = getifaddrs(&addrs) == 0;
if (success) {
cursor = addrs;
while (cursor != NULL) {
if ((cursor->ifa_flags & IFF_LOOPBACK) == 0 ) {
printf("%s ", (char *)cursor->ifa_name);
printf("%s\n",inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr));
}
if ( (cursor->ifa_addr->sa_family == AF_LINK)
&& (((const struct sockaddr_dl *) cursor->ifa_addr)->sdl_type ==IFT_ETHER)
) {
dlAddr = (const struct sockaddr_dl *) cursor->ifa_addr;
// fprintf(stderr, " sdl_nlen = %d\n", dlAddr->sdl_nlen);
// fprintf(stderr, " sdl_alen = %d\n", dlAddr->sdl_alen);
base = (const uint8_t *) &dlAddr->sdl_data[dlAddr->sdl_nlen];
printf(" MAC address ");
for (i = 0; i < dlAddr->sdl_alen; i++) {
if (i != 0) {
printf(":");
}
printf("%02x", base[i]);
}
printf("\n");
}
cursor = cursor->ifa_next;
}
}
return 0;
}

 
 
 
There are also iPhone device info from the SDK in UIDevice.h
UIDevice.h Select all

+ (UIDevice *)currentDevice;
@property(nonatomic,readonly,retain) NSString *name; // e.g. "My iPhone"
@property(nonatomic,readonly,retain) NSString *model; // e.g. @"iPhone", @"iPod Touch"
@property(nonatomic,readonly,retain) NSString *localizedModel; // localized version of model
@property(nonatomic,readonly,retain) NSString *systemName; // e.g. @"iPhone OS"
@property(nonatomic,readonly,retain) NSString *systemVersion; // e.g. @"2.0"
@property(nonatomic,readonly) UIDeviceOrientation orientation; // return current device orientation
@property(nonatomic,readonly,retain) NSString *uniqueIdentifier; // a string unique to each device based on various hardware info.

undocumented
- (id)buildVersion;
- (int)batteryState;





 
 
 

Monday, January 12, 2009

How-to do ARM GCC Inline Assembler for iPhone

The following code demonstrates an example to write Inline Assembler in llvm-gcc for iPhone ARM

arithmetic_shift_right.c Select all

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
int i = atoi(argv[1]);
asm volatile ("mov %0, %1, ASR #1" : "=r"(i) : "r"(i));
printf("arithmetic_shift_right is %d\n", i);
exit(0);
}


The general format (ref) is
asm volatile (assembler instructions : output operands (optional) : input operands (optional) : clobbered registers (optional) );

e.g.
asm volatile ("mul %0, %1, %2" : "=r" (result) : "r" (number1) , "r" (number2));


This version is for Assembler Macro

arithmetic_shift_right.c Select all

#include <stdio.h>
#include <stdlib.h>

inline int arithmetic_shift_right(int a) {
int y;
__asm__("mov %0, %1, ASR #1" : "=r" (y) : "r" (a));
// Register R0 will become the value of register R1 shifted to the right by 1 bit, with the sign maintained.
return y;
}

int main(int argc, char *argv[]) {
int i = atoi(argv[1]);
printf("arithmetic_shift_right %d is %d\n", i, arithmetic_shift_right(i));
exit(0);
}



Below is the otool output for Assembler Macro
otool -tV Select all

_arithmetic_shift_right:
00001eb4 e92d4080 stmdb sp!, {r7, lr}
00001eb8 e28d7000 add r7, sp, #0 ; 0x0
00001ebc e24dd008 sub sp, sp, #8 ; 0x8
00001ec0 e58d0000 str r0, [sp]
00001ec4 e59d3000 ldr r3, [sp]
00001ec8 e1a030c3 mov r3, r3, asr #1       @@ arithmetic shift right
00001ecc e58d3004 str r3, [sp, #4]
00001ed0 e59d3004 ldr r3, [sp, #4]
00001ed4 e1a00003 mov r0, r3
00001ed8 e247d000 sub sp, r7, #0 ; 0x0
00001edc e8bd8080 ldmia sp!, {r7, pc}


Below is the otool output for Assembler Macro (after full optimzation -O2)
otool -tV Select all

_arithmetic_shift_right:
00001f04 e1a000c0 mov r0, r0, asr #1
00001f08 e12fff1e bx lr




Assembler Macro for more than one assembler instruction
arithmetic shift right then perform 16 bit binary multiplication

Assembler Macros Select all

__asm__("mov %0, %1, ASR #1\n\t"
"mul %0, %0, %1"
: "=r" (y) : "r" (a));





Wednesday, January 7, 2009

Enable Emoji without jailbreak iPhone

There is no need to guess and wait for update. This patch works for firmware 2.2 / 2.2.1

Emoji is the Japanese name for pictorial characters, smileys and emoticons. The characters are similar to the commonly used emoticons but Emoji contains over 461 icons. These icons are standardized and built into most japanese handsets.



Currently, this new feature for firmware 2.2 is available to Japanese iPhone 3G or jailbreak iPhone with emoji patch only.

To enable Emoji without jailbreak, you need to install an app that I made.

This is not a vcard.vcf method, this is a patch like the one in Cydia but available to iPhone and no jailbreak required. The above screen dump is directly captured from my iPhone 3G, and no jailbreak.


Touch Dial Emoji Version 1.2

To enable Emoji, follow these steps
(1) Upgrade iPhone firmware to 2.2

(2) Install Touch Dial Emoji version 1.2 from App Store
iTunes Link http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=286534260&mt=8

Yes, you have to pay for this app. If you don't like to pay, jailbreak your iPhone and install the package from Cydia, it is free.

(3) Goto Settings -> Touch Dial -> turn Enable Smiley icon to ON


(4) Launch Touch Dial

(5) Go to Settings>General>Keyboard>International Keyboards>Japanese and enable "Emoji."




The difficulty of this app is not on coding as the method is well known, it is about how to get it past.

One more thing, new hack is coming.

CodeSign error: a valid provisioning profile is required

"CodeSign error: a valid provisioning profile is required for product type 'Application' in SDK 'Device - iPhone OS 2.2"

This error will appear when you update your provisioning profile in iPhone SDK 2.2
or after the expiration of developer certificate and that you have a new provisioning profile from the developer portal

This is the solution (which is modified from http://www.furmanek.net/54/iphone-sdk-22-codesign-error/)

Suppose you have copied your provisioning profile called "iPhone_Development.mobileprovision" to the Library folder and build & go an old iPhone project called "MyApp", and this annoying error appears

(1) cd ~/Library/MobileDevice/Provisioning\ Profiles/

(2) find out the UUID of the provisioning profile
strings iPhone_Development.mobileprovision | grep "<string>.*-.*</string>"

output is like this
<string>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</string>

(3) copy that UUID between the string tag

(4) close xcode and go to your project
cd ~/Projects/MyApp/MyApp.xcodeproj

(5) Use a text editor to open the project.pbxproj
find the string PROVISIONING_PROFILE

paste the UUID that you copied from step (3) and put it in both Debug and Release Sections (do multiple finds) for the following line
e.g.
PROVISIONING_PROFILE = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

(6) Launch XCode and open the project and build & go again


Updates :
Deleting all of the lines "PROVISIONING_PROFILE" in project.pbxproj will also fix the problem for iPhone SDK 3 or above





Sunday, January 4, 2009

UICatalog : Makefile for Apple sample iPhone SDK code

To check out UICatalog from Apple developer website or from here
svn co -r16 http://apiexplorer.googlecode.com/svn/trunk/UICatalog UICatalog

The modification here is to show how to change the xib file to iphone code (as in revision 17) here
http://code.google.com/p/apiexplorer/source/detail?r=17

Furthermore, if you checkout the revision 18, you can have the ldid binary and Makefiles for installation to iPhone /Applications folder
Mac : (using Makefile.mac and ldid_mac)
Linux toolchain : (using Makefile.linux and ldid_linux)
iPhone gcc : (using Makefile.iphone and please install ldid package in Cydia)

Instructions to compile using Makefile for UICatalog under Mac
(1) Checkout revision 18
svn co -r18 http://apiexplorer.googlecode.com/svn/trunk/UICatalog UICatalog

(2) Install respring in iPhone (if haven't done so) assume your iphone ip is 10.0.2.2
make install_respring -f Makefile.mac IPHONE_IP=10.0.2.2

(3) modify the IPHONE_IP (to the actual IP address of iPhone) in Makefile.mac
IPHONE_IP=10.0.2.2

(4) make & install
make -f Makefile.mac
make install -f Makefile.mac


If you want to install your Mac / Linux public key in iPhone so as to avoid typing password using ssh, please refer to my previous post here

Instructions to compile using Makefile for UICatalog under Linux toolchain

Please refer to these two articles in how to install toolchain in Linux
http://iphonesdkdev.blogspot.com/2008/11/upgrade-vmware-image-to-ubuntu-810-for.html
http://iphonesdkdev.blogspot.com/2008/10/how-to-install-llvm-gcc-for-iphone-sdk.html

(1) Checkout revision 18
svn co -r18 http://apiexplorer.googlecode.com/svn/trunk/UICatalog UICatalog

(2) Install respring in iPhone (if haven't done so) assume your iphone ip is 10.0.2.2
make install_respring -f Makefile.linux IPHONE_IP=10.0.2.2

(3) modify the IPHONE_IP (to the actual IP address of iPhone) and toolchain (to the toolchain folder location) in Makefile.linux
IPHONE_IP=10.0.2.2
toolchain=/usr/toolchain2


(4) make & install
make -f Makefile.linux
make install -f Makefile.linux


If you want to install your Mac / Linux public key in iPhone so as to avoid typing password using ssh, please refer to my previous post here

Instructions to compile using Makefile for UICatalog under iPhone gcc
Assume already install iphone gcc, ldid, make and subversion packages in Cydia and also have sdk headers / lib files

(1) Checkout revision 18
svn co -r18 http://apiexplorer.googlecode.com/svn/trunk/UICatalog UICatalog

(2) Install respring in iPhone (if haven't done so)
make install_respring -f Makefile.iphone

(3) modify the SDK (to the sdk headers and lib files location) in Makefile.iphone
SDK = /var/toolchain2/sys20

(4) make & install
make -f Makefile.iphone
make install -f Makefile.iphone


P.S. There is a great tool here to convert .xib / *.nib to .m
see here
http://github.com/akosma/nib2objc/tree/master


If you need to compile ldid in Intel machine, here is how

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


For PowerPC, you need the patch file here
http://fink.cvs.sourceforge.net/viewvc/*checkout*/fink/dists/10.4/unstable/crypto/finkinfo/ldid.patch?revision=1.1

and to apply the patch before compilation, use this

curl -O http://svn.telesphoreo.org/trunk/data/ldid/ldid-1.0.476.tgz
tar -zxf ldid-1.0.476.tgz
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


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






Friday, January 2, 2009

How-to create svn server (subversion) in iPhone

This guide shows you how to setup svn+ssh server in pwned iPhone

(1) Install subversion package in Cydia
apt-get install subversion

(2) create repository in iPhone (e.g. with the Project called UICatalog)

mkdir -p /var/root/Library/Subversion/Repository
svnadmin create /var/root/Library/Subversion/Repository/UICatalog
mkdir -p /tmp/UICatalog/trunk /tmp/UICatalog/branches /tmp/UICatalog/tags
svn import /tmp/UICatalog/ file:///var/root/Library/Subversion/Repository/UICatalog -m "Create Directory Structure"
rm -rf /tmp/UICatalog


(3) Import Project directory
import from iPhone
svn import UICatalog file:///var/root/Library/Subversion/Repository/UICatalog/trunk -m "Import project dir from iPhone"

import from Mac (assume iPhone IP is 10.0.2.2)
svn import UICatalog svn+ssh://root@10.0.2.2/var/root/Library/Subversion/Repository/UICatalog/trunk -m "Import project dir from Mac"

(4) Checkout Project directory
checkout to Mac (assume iPhone IP is 10.0.2.2)
svn checkout svn+ssh://root@10.0.2.2/var/root/Library/Subversion/Repository/UICatalog/trunk UICatalog

checkout a specific revision 5 to Mac (assume iPhone IP is 10.0.2.2)
svn co -r 5 svn+ssh://root@10.0.2.2/var/root/Library/Subversion/Repository/UICatalog/trunk UICatalogR2

checkout to iPhone to another dir
svn checkout file:///var/root/Library/Subversion/Repository/UICatalog/trunk UICatalog2

checkout a specific revision 5 to iPhone
svn co -r 5 file:///var/root/Library/Subversion/Repository/UICatalog/trunk UICatalog_v5


(5)Other useful svn commands
(change directory to the working copy that was checkout in iPhone)
cd UICatalog2
svn info
svn commit -m 'commit changes'
svn ls file:///var/root/Library/Subversion/Repository/UICatalog/trunk
svn log


(change directory to the working copy that was checkout in Mac)
cd UICatalog
svn add newfile.m
svn info
svn commit -m 'commit changes'
svn ls svn+ssh://root@10.0.2.2/var/root/Library/Subversion/Repository/UICatalog/trunk
svn log


(6) svn to googlecode.com
svn checkout https://<yourproject>.googlecode.com/svn/trunk/<yourprojectdirname> --username <your username without @gmail.com>

When prompted, enter your generated googlecode.com password.
The googlecode.com svn password is in the googlecode.com (it is not the same as the gmail password)

Profile -> Settings

cd <yourprojectdirname>
svn add newfile.m
svn commit -m 'commit changes: adding newfile.m'


import to a subdirectory
svn import <yourprojectdirname> https://<yourproject>.googlecode.com/svn/trunk/<yourprojectdirname>/ --username <your username without @gmail.com> -m 'commit changes: importing'

delete directory/files that were in the wrong place
svn delete -m "Deleting wrong place commit" https://<yourproject>.googlecode.com/svn/trunk/<directorytobedeleted> https://<yourproject>.googlecode.com/svn/trunk/<filetobedeleted> ....

(7) Others
The use of Xcode 3 and subversion is in Apple documentation here
http://developer.apple.com/mac/articles/server/subversionwithxcode3.html

You can make use of this to manage SCM for XCode project to google code, Mac or iPhone


(8) GIT
If you need git on leopard, here
http://code.google.com/p/git-osx-installer/
or use MacPorts (port install git-core)

or you can compile and install from source

mkdir ~/src
cd ~/src/
curl -O http://kernel.org/pub/software/scm/git/git-1.6.5.3.tar.bz2
tar -xjvf git-1.6.5.3.tar.bz2
cd git-1.6.5.3
./configure --prefix=/usr/local
make
sudo make install
git --version





Thursday, January 1, 2009

XCode Template for cocos2d

This open source game Libray is for you to development games for iPhone using XCode. The current version is 0.6.2

The project source is here
http://code.google.com/p/cocos2d-iphone/

These are the features of the library:
* Scene management (workflow)
* Transitions between scenes
* Sprites
* Actions
* Basic menus and buttons
* Integrated Chipmunk 2d physics engine
* Particle system
* Text rendering support
* Texture Atlas support
* Tile Map support
* Parallax scrolling
* Touch/Accelerometer support
* Portrait and Landscape mode
* Integrated Pause/Resume
* Supports PowerVR Texture Compression (PVRTC) format
* Language: objective-c
* Open Source: Compatible with open and closed source projects
* OpenGL ES 1.1 based

Here is the XCode Template, so that you can create new project and start 2d game programming

Installation Instruction of this XCode Template for cocos2d 0.62

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


Here is a quick primer guide to start development with a simple game using cocos2d, this XCode template is also created based on the method as described in this article
http://monoclestudios.com/cocos2d_whitepaper.html
and these two as well
http://lethain.com/entry/2008/oct/03/notes-on-cocos2d-iphone-development/
http://lethain.com/entry/2008/oct/20/touch-detection-in-cocos2d-iphone/

After installation of this XCode Template, you can create new project for cocos2d library

A Makefile is also included so that you can build the created new project and ldid fake codeign and install in the /Application folder of iPhone

(1) you need to change the IPHONE_IP in the Makefile
(2) make install_respring
(3) make
(4) make install

If you want to install your Mac public key in iPhone so as to avoid typing password using ssh, please refer to my previous post here

The api documentation of cocos2d are here
http://groups.google.com/group/cocos2d-iphone-discuss

Update : Cocos2d v0.7 XCode Template

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


This new XCode Template v0.7 has been restructured so that when cocos2d is updated in the future, you can just copy the new cocos2d directory and replace the cocos2d-iphone in the old project directory e.g.


cp -r ~/Downloads/cocos2d-iphone-0.8/* ~/Projects/myproject/cocos2d-iphone/
rm -fr ~/Projects/myproject/cocos2d-iphone/cocos2d-iphone.xcodeproj