Saturday, December 26, 2009

iPhone SDK 3.0 API Explorer

The previous version is for OS 2.2 and is here
http://iphonesdkdev.blogspot.com/2008/12/iphone-sdk-api-explorer.html

It is now updated to support OS 3.0 and with on-line reference to Erica Sadun 3.1.2 class documentation

Installation Instructions:

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

Updated source code for version 3.0 is here
svn checkout http://apiexplorer.googlecode.com/svn/trunk/apiexplorer3

or download it (revision 25) here
http://apiexplorer.googlecode.com/files/apiexplorer3.zip

The project can be built using Xcode or iphone gcc. The Makefile has been updated, so that it can be compiled under iphone gcc for 3.0 framework. Refer here for the 3.0 headers for iphone gcc.

The Cydia version did not have all the frameworks (e.g. GameKit and others). To explore more frameworks, you need to download the source code and build your own version.

For Xcode, just add the required frameworks before build. For iphone gcc, just add LDFLAGS (like the one below) in the Makefile and then make install.

LDFLAGS += -framework GameKit

If you want to have on-line reference to 3.0.0 framework instead of 3.1.2 from Erica's website, you should build your code.plist. Here is the script to dump the dictionary key-string pairs for 3.0.0

#!/bin/sh
curl -s -L http://ericasadun.com/iPhoneDocs300/annotated.html | grep "tr..td" | sed -e "s/^.*href=\"\(.*html\)\".\(.*\)\/a.*$/\<key\>\2\/key\>\<string\>\1\<\/string\>/g;"




This is how to dump the method name to class key-string values
method2class.plist Select all

#!/bin/sh
for page in "" _0x61 _0x62 _0x63 _0x64 _0x65 _0x66 _0x67 _0x68 _0x69 _0x6a _0x6b _0x6c _0x6d _0x6e _0x6f _0x70 _0x71 _0x72 _0x73 _0x74 _0x75 _0x76 _0x77 _0x78 _0x79 _0x7a ; do
curl -s -L http://ericasadun.com/iPhoneDocs312/functions_func${page}.html | awk '/^.li./{s=$0;next}{print s " "$0}' | sed -e "s/^.li.\(.*\)\s[:,].*a\sclass..el..href..*html.*\">\(.*\)<\/a>$/\<key\>\1\<\/key\>\<array\>\<string\>\2\<\/string\>\<\/array\>/g;" | grep "<key>" | sed -e "s/(.*)//g" | awk -F "</key>" '!arr[$1] {arr[$1] = $0; next} {arr[$1] = arr[$1] " " $2} END {for(i in arr) {print arr[i]}}' | sed -e "s/<\/array> <array>//g"
done



Latest screen dump for version 3.1 (not yet released)






Wednesday, December 9, 2009

[How-to] compile SmartScreen widget in iphone gcc

Here is a sample clock widget source from SmartScreen sdk http://media-phone.ch/en/software/smartscreen/sdk/ , I added a Makefile so that it can be compiled under iphone gcc

http://apiexplorer.googlecode.com/files/ClockWidget.zip

Make sure you have installed iphone gcc and 3.0 headers (refer here for the 3.0 headers) and also SmartScreen (Lite or full version) before your testing.

If you have installed toolchain and 3.0 headers under cygwin or linux, just modify the sdk location in the Makefile and it should compile as well.

SmartScreen widget will be installed under the folder /var/mobile/Library/SmartScreen

To compile and install this sample clock widget under iphone gcc

make
make install


To uninstall the clock widget

make uninstall


This is the updated Makefile for SmartScreen ClockWidget
Makefile Select all

# Makefile for gcc compiler for iPhone (SmartScreen Widget)

PROJECTNAME:=Clock
PRINCIPALCLASS:=$(PROJECTNAME)Widget
WIDGETFOLDER:=$(PROJECTNAME).wdgt
INSTALLFOLDER:=/var/mobile/Library/SmartScreen
MINIMUMVERSION:=3.0

CC:=arm-apple-darwin9-gcc
CPP:=arm-apple-darwin9-g++
LD:=$(CC)
SDK:=/var/toolchain/sys30

LDFLAGS = -arch arm -lobjc
LDFLAGS += -framework CoreFoundation
LDFLAGS += -framework Foundation
LDFLAGS += -framework UIKit
LDFLAGS += -framework CoreGraphics
//LDFLAGS += -framework AddressBook
//LDFLAGS += -framework AddressBookUI
//LDFLAGS += -framework AudioToolbox
//LDFLAGS += -framework AudioUnit
//LDFLAGS += -framework AVFoundation
//LDFLAGS += -framework CoreSurface
//LDFLAGS += -framework CoreAudio
//LDFLAGS += -framework CoreData
//LDFLAGS += -framework CFNetwork
//LDFLAGS += -framework GraphicsServices
//LDFLAGS += -framework OpenAL
//LDFLAGS += -framework OpenGLES
//LDFLAGS += -framework MediaPlayer
//LDFLAGS += -framework QuartzCore
//LDFLAGS += -framework Security
//LDFLAGS += -framework SystemConfiguration
//LDFLAGS += -framework WebCore
//LDFLAGS += -framework WebKit
//LDFLAGS += -framework SpringBoardUI
//LDFLAGS += -framework TelephonyUI
//LDFLAGS += -framework JavaScriptCore
//LDFLAGS += -framework PhotoLibrary
LDFLAGS += -L"$(SDK)/usr/lib"
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
LDFLAGS += -mmacosx-version-min=10.5
LDFLAGS += -dynamiclib

CFLAGS += -I"$(SDK)/usr/include"
CFLAGS += -DDEBUG -std=gnu99 -O0
CFLAGS += -Diphoneos_version_min=$(MINIMUMVERSION)
CFLAGS += -Wno-attributes -Wno-trigraphs -Wreturn-type -Wunused-variable

BUILDDIR=./build/$(MINIMUMVERSION)
SRCDIR=./
RESDIR=./Resources
OBJS+=$(patsubst %.m,%.o,$(wildcard $(SRCDIR)/*.m))
OBJS+=$(patsubst %.c,%.o,$(wildcard $(SRCDIR)/*.c))
OBJS+=$(patsubst %.mm,%.o,$(wildcard $(SRCDIR)/*.mm))
OBJS+=$(patsubst %.cpp,%.o,$(wildcard $(SRCDIR)/*.cpp))
OBJS+=$(patsubst %.m,%.o,$(wildcard ./*.m))
PCH=$(wildcard *.pch)
RESOURCES=$(wildcard $(RESDIR)/*)

CFLAGS += $(addprefix -I,$(SRCDIR))

CPPFLAGS=$CFLAGS

all: $(PROJECTNAME)

$(PROJECTNAME): $(OBJS) Makefile
    $(LD) $(LDFLAGS) $(filter %.o,$^) -o $@

%.o: %.m %.h $(PCH) $(filter-out $(patsubst %.o,%.h,$(OBJS)), $(wildcard $(SRCDIR)/*.h))
    $(CC) --include $(PCH) -c $(CFLAGS) $< -o $@

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

%.o: %.mm %.h $(PCH) $(filter-out $(patsubst %.o,%.h,$(OBJS)), $(wildcard $(SRCDIR)/*.h))
    $(CPP) --include $(PCH) -c $(CPPFLAGS) $< -o $@

%.o: %.cpp %.h $(PCH)
    $(CPP) --include $(PCH) -c $(CPPFLAGS) $< -o $@

dist: $(PROJECTNAME) Info.plist Makefile $(RESOURCES)
    @rm -rf $(BUILDDIR)
    @mkdir -p $(BUILDDIR)/$(WIDGETFOLDER)
ifneq ($(RESOURCES),)
    @-cp -r $(RESOURCES) $(BUILDDIR)/$(WIDGETFOLDER)
    @-$(foreach DIR, .svn .DS_Store .git* , find $(BUILDDIR)/$(APPFOLDER) -name '$(DIR)' -prune -exec rm -rfv {} \;;)
endif
    @cp Info.plist $(BUILDDIR)/$(WIDGETFOLDER)/Info.plist
    @./plutil -key CFBundleExecutable -value $(PROJECTNAME) $(BUILDDIR)/$(WIDGETFOLDER)/Info.plist
    @./plutil -key CFBundleName -value $(PROJECTNAME) $(BUILDDIR)/$(WIDGETFOLDER)/Info.plist
    @./plutil -key NSPrincipalClass -value $(PRINCIPALCLASS) $(BUILDDIR)/$(WIDGETFOLDER)/Info.plist
    ldid -S $(PROJECTNAME)
    @mv $(PROJECTNAME) $(BUILDDIR)/$(WIDGETFOLDER)

install: dist
    @rm -fr $(INSTALLFOLDER)/$(WIDGETFOLDER)
    cp -r $(BUILDDIR)/$(WIDGETFOLDER) $(INSTALLFOLDER)/
    @chown -R mobile:mobile $(INSTALLFOLDER)/$(WIDGETFOLDER)
    @echo "Widget $(WIDGETFOLDER) installed, please respring device"
    @./respring

uninstall:
    @rm -fr $(INSTALLFOLDER)/$(WIDGETFOLDER)
    @./respring
    @echo "Widget $(WIDGETFOLDER) uninstalled, please respring device"

install_respring:
    cp ./respring /usr/bin/respring

distclean:
    @rm -rf $(BUILDDIR)

clean:
    @rm -f $(OBJS)
    @rm -rf $(BUILDDIR)
    @rm -f $(PROJECTNAME)

.PHONY: all dist install uninstall install_respring distclean clean





Wednesday, November 25, 2009

Google Wave, Drag and Drop ?

Want to enable drag and drop in google wave for your browser ?



Install google gears here

http://gears.google.com









Monday, November 23, 2009

Where is Cycript ?

Cycrypt is a new project that blends Objective-C and JavaScript to make it easier to implement aspects of both together.
and here it is

http://www.cycript.org/

Examples are here

http://www.cycript.org/examples/


Dial with Cycript: [SBTTYPromptAlert dialNumberPromptingIfNecessary:"+18885551234" addressBookUID:-1 urlAddition:"wasLockAlert=1"];






Sunday, November 22, 2009

How to create local and remote ssh git repo in Mac OS X

(1) Install git for Mac OS X

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


(2) Create localrepo in local harddisk / SMB Share (assume already init as a repository)
init as a git repository

cd ~/myproject
git init
git add .
git rm -r --cache build     # ignore the build directory for iPhone project
git commit -m 'Initial commit'


git mkdir -p ~/git
git clone --bare ~/myproject ~/git/myproject.git
touch ~/git/myproject.git/git-daemon-export-ok


git mkdir -p /Volumes/Data/GIT
git clone --bare ~/myproject /Volumes/Data/GIT/myproject.git
touch /Volumes/Data/GIT/myproject.git/git-daemon-export-ok

push to localrepo

cd ~/myproject
git remote add localrepo ~/git/myproject.git
git push localrepo master
git log


(3) Suppose you have a project in ~/myproject
and the remote ssh server login is user@xxx.xxx.xxx.xxx
both client and server have git installed

(4) Create sshrepo in remote server over ssh

ssh user@xxx.xxx.xxx.xxx "mkdir -p /Volumes/HD/git/myproject.git; cd /Volumes/HD/git/myproject.git; git --bare init; touch git-daemon-export-ok"


check the location of remote git binary and the remote ssh login shell


ssh user@xxx.xxx.xxx.xxx "which git-upload-pack"
ssh user@xxx.xxx.xxx.xxx "echo \$PATH"


mine is /usr/local/bin/git-upload-pack


if the remote login shell does not include path of git, create ~/.bashrc in your remote ssh login shell


ssh user@xxx.xxx.xxx.xxx "echo 'export PATH=\${PATH}:/usr/local/bin' > ~/.bashrc"


push to sshrepo

cd ~/myproject
git remote add sshrepo ssh://user@xxx.xxx.xxx.xxx/Volumes/HD/git/myproject.git
git push sshrepo master
git log



Test git clone

cd ~
git clone ~/git/myproject.git workinglocal
cd workinglocal
git log


or


cd ~
git clone ssh://user@xxx.xxx.xxx.xxx/Volumes/HD/git/myproject.git workingremote
cd workingremote
git log


How to Branch

git branch -r                 # show branch in repo
git checkout -b todo origin/to-do-branch # checkout a new branch
git checkout master           # checkout the master branch

git checkout localrepo/master # checkout the master branch in localrepo
git checkout sshrepo/master   # checkout the master branch in sshrepo

git branch next               # create new branch
git add .
git commit -m 'commit nextbranch'
git push localrepo next

git branch -b cygwin
git branch -r
git add *
git commit -m 'commit cygwin branch'
git push origin cygwin


How to checkout a previous commit

git log # show log of previous commit
git log --format=oneline # show log of previous commit log hex digit
git checkout 838fbf2e9b050d2350694235bbf5e9a11fa7acea # commit log hexdigit
git checkout 838fbf2e9b050d2350694235bbf5e9a11fa7acea -- file1/to/restore file2/to/restore # checkout files to restore


How to push to github

git config --global user.name "javacom"
git config --global user.email "javacomhk@yahoo.com"
git remote rm origin
git remote add origin git@github.com:javacom/toolchain4.git
git push origin master









Sunday, October 4, 2009

How to compile mobilesubstrate extension in iPhone gcc for OS 3.0

(1) You need iphone gcc installed in your jailbroken iPhone / iPod Touch with firmware 3.0 or above

iPhone gcc is available in Cydia. To install it in you need to do these


# assume you have installed APT 0.6 Transitional and Aptitude and wget in Cydia, so that you can use the command apt-get
# if libgcc is broken in Cydia, you have to install it manually before iphone-gcc
wget http://apt.saurik.com/debs/libgcc_4.2-20080410-1-6_iphoneos-arm.deb
dpkg -i libgcc_4.2-20080410-1-6_iphoneos-arm.deb
# install iphone-gcc
apt-get install iphone-gcc


Moreover, you need these utilities as well


apt-get install make ldid zip unzip wget


for editor in iPhone you can use vim or nano

(2) You need the header files of toolchain and SDK 3.0, libsubstrate and classdump the SpringBoard and UIKit headers

The building of iPhone gcc in Linux and header files (updated for OS 3.0) is here in
http://www.saurik.com/id/4

The updated mobilesubtrate header files are here

The classdump procedure is here

But all these involved a lot of downloading and patching, so I put all the downloading/classdump/patching in one zipped tar file (sys30.tgz). You can download it (about 96M) here

(3) copy and untar the required headers and libraries (say copy to /var/mobile/sys30.tgz) and install it in iPhone / iPod Touch say

mkdir /var/toolchain/
cd /var/toolchain/
tar -xzvf /var/mobile/sys30.tgz


(4) Use this sample mobilesubstrate extension (ExampleHook.zip) and unzip it to test. You need to apt-get install mobilesubstrate in iPhone / iPod Touch first

http://apiexplorer.googlecode.com/files/ExampleHook.zip

apt-get install mobilesubstrate
wget http://apiexplorer.googlecode.com/files/ExampleHook.zip
unzip ExampleHook.zip
cd ExampleHook

make (to compile and codesign)
make install (to install), after install you need respring the device to test
make uninstall (to uninstall), after uninstall you need respring as well

respring utility is available from my cydia source http://cydia.iphone.org.hk/apt/

(5) You can also checkout a copy of the iphone backgrounder to test your iphone gcc and mobilesubstrate development environment
http://code.google.com/p/iphone-backgrounder/source/checkout

Install subversion before using svn in iPhone / iPod Touch

apt-get install subversion
svn checkout http://iphone-backgrounder.googlecode.com/svn/trunk/ iphone-backgrounder
cd iphone-backgrounder



I use this modified Makefile to compile iphone-backgrounder
MakefileSelect all

NAME = Backgrounder
APP_ID = jp.ashikase.backgrounder

# These paths must be changed to match the compilation environment
TOOLCHAIN = /var/toolchain/sys30/dump
SYS_PATH = /var/toolchain/sys30
MS_PATH = /var/toolchain/sys30/mobilesubstrate
INC_PATH = /var/toolchain/sys30/usr/include
LDID = /usr/bin/ldid

CXX = arm-apple-darwin9-g++
CXXFLAGS = -g0 -O2 -Wall -Werror -Wno-write-strings -include common.h -DAPP_ID=\"$(APP_ID)\"
LD = $(CXX)
LDFLAGS = -march=armv6 \
-mcpu=arm1176jzf-s \
-bind_at_load \
-multiply_defined suppress \
-framework CoreFoundation \
-framework Foundation \
-framework UIKit \
-framework GraphicsServices \
-framework CoreGraphics \
-F$(SYS_PATH)/System/Library/Frameworks \
-F$(SYS_PATH)/System/Library/PrivateFrameworks \
-L$(SYS_PATH)/usr/lib -lsubstrate \
-lobjc

INCLUDES = -I$(INC_PATH) -I$(MS_PATH) -I$(TOOLCHAIN) \
-I./Classes

SUBDIRS = . Classes

DIRLIST := $(SUBDIRS:%=%)
SRCS := $(foreach dir,$(DIRLIST), $(wildcard $(dir)/*.mm))
HDRS := $(foreach dir,$(DIRLIST), $(wildcard $(dir)/*.h))
OBJS := $(SRCS:.mm=.o)

all: $(NAME).dylib

config:
ln -snf $(TOOLCHAIN) $(SYS_PATH)

# Replace 'iphone' with the IP or hostname of your device
install: config $(NAME).dylib
ssh root@iphone rm -f /Library/MobileSubstrate/DynamicLibraries/$(NAME).dylib
scp $(NAME).dylib root@iphone:/Library/MobileSubstrate/DynamicLibraries/
ssh root@iphone restart

$(NAME).dylib: $(OBJS) $(HDRS)
$(LD) -dynamiclib $(LDFLAGS) $(OBJS) -init _$(NAME)Initialize -o $@
$(LDID) -S $@

%.o: %.mm
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

clean:
rm -f $(OBJS) $(NAME).dylib


P.S. This is how to compile a standard c++ program in iPhone gcc
test.cppSelect all

arm-apple-darwin9-g++ -I"/var/toolchain/sys30/usr/include" -I"/var/toolchain/sys30/usr/include/c++/4.2.1" -I"/var/toolchain/sys30/usr/include/c++/4.2.1/armv6-apple-darwin9" -g0 -O2 -Wall -L"/var/toolchain/sys30/usr/lib" -march=armv6 -mcpu=arm1176jzf-s test.cpp -o test






Sunday, August 2, 2009

Compatible code for OS 2.2.1 and 3.0

Recently, the itts apple server has a number of changes and one of my favourite opensource app AppSales Mobile failed to get the sales data. It is now updated and thanks to the developer for the updating

http://github.com/omz/AppSales-Mobile/


However, the project was set to compile for SDK3.0, there are only a few changes that need to bring this app to be compatible to OS 2.2.1 and 3.0 at the same time.

Here are the steps involved

(1) Base SDK set to iPhone Device 3.0
(2) In Project Settings, iPhone OS Deployment Target set to iPhone OS 2.2.1
(3) Change the source code in RootViewController.m that have setFont or setImage methods, there are about 18 such changes to be done.


This is how to change the source code by adding respondsToSelector: test before using the deprecated method



change from


  [footer.titleLabel setFont:[UIFont systemFontOfSize:14.0]];


to


  if ( [footer respondsToSelector:@selector(setFont:)] ) {
    [footer setFont:[UIFont systemFontOfSize:14.0]];
  }
  else {
    [footer.titleLabel setFont:[UIFont systemFontOfSize:14.0]];
  }




change from

  cell.imageView.image = [UIImage imageNamed:@"Daily.png"];


to


  if ( [cell respondsToSelector:@selector(setImage:)] ) {
    cell.image = [UIImage imageNamed:@"Daily.png"];
  }
  else {
    cell.imageView.image = [UIImage imageNamed:@"Daily.png"];
  }


You may get warnings when build to actual 2.2.1 OS device, but this is normal. However, you cannot build to 2.2.1 Simulator.

The modified source is available here
http://code.google.com/p/apiexplorer/source/detail?r=20

Revision 20 is a modified source (as above) for version 2009/7

Revision 23 is the updated modification for version 2009/11/19

to checkout a revision

svn checkout -r 20 http://apiexplorer.googlecode.com/svn/branches/AppSalesMobile221 AppSalesMobile221r20
svn checkout -r 23 http://apiexplorer.googlecode.com/svn/branches/AppSalesMobile221 AppSalesMobile221r23



If you want to check out a previous version based on the commit hexdigit from the github repo, do this

git clone git://github.com/omz/AppSales-Mobile.git AppSales0731
cd AppSales0731
git checkout -b b0731 ff248e8e6c23386f867514c1c331a469b7d4cf45
git log