Sunday, October 30, 2011

How to install perl, theos and iphone-gcc in iPhone

(1) Install the following packages in Cydia
APT 0.6 Transitional (and all its dependencies)
wget

(2) Use SSH login shell commands to install perl & theos (or install them in Cydia by adding Sources)

echo "deb http://coredev.nl/cydia iphone main" > /etc/apt/sources.list.d/coredev.nl.list
wget http://coredev.nl/cydia/coredev.pub
apt-key add coredev.pub
apt-get update
apt-get install perl
echo "deb http://nix.howett.net/theos ./" > /etc/apt/sources.list.d/howett.net.list
apt-get update
apt-get install net.howett.theos rsync


If you have No space left on device error when installing perl , relocate /usr/local to /var/stash/local

(3) Use SSH login shell commands to install iphone-gcc and ldid (or install them in Cydia)

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
apt-get update
apt-get install iphone-gcc
apt-get install make ldid zip unzip com.ericasadun.utilities


(4) Download SDK3.2 Headers and Libs from here
Please take note that the current iPhone-gcc does not support iOS SDK 4.0 or above

(5) copy iPhoneSDKHeadersAndLibs_32.pkg to iPhone

(6) Install SDK and additional libraries to sdk

apt-get update
apt-get install xar cpio
xar -xf iPhoneSDKHeadersAndLibs_32.pkg Payload
cat Payload | zcat | cpio -id
mv Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk /var/sdk
cd /var/sdk/usr/lib/
ln -s libstdc++.6.dylib libstdc++.dylib
ln -s crt1.o crt1.10.5.o
ln -s dylib1.o dylib1.10.5.o
cp -p /usr/lib/libgcc_s.10.5.dylib .



(7) Create a command line tool project

/var/theos/bin/nic.pl helloworld


(8) Choose [4.] iphone/tool

(9) Edit main.mm and add printf and cout like this
main.mm Select all

#include <iostream>
using namespace std;
int main(int argc, char **argv, char **envp) {
    printf("Hello World\n");
    cout << "Hello CPP" << endl;
    return 0;
}


(10) Add the ADDITIONAL_CFLAGS and ADDITIONAL_CCFLAGS in Makefile like this
Makefile (Tool) Select all

export THEOS=/var/theos
include $(THEOS)/makefiles/common.mk

TOOL_NAME = helloworld
helloworld_FILES = main.mm

ADDITIONAL_CFLAGS = -I"$(SYSROOT)/usr/lib/gcc/arm-apple-darwin10/4.2.1/include"
ADDITIONAL_CCFLAGS = -I"$(SYSROOT)/usr/include/c++/4.2.1"
ADDITIONAL_CCFLAGS += -I"$(SYSROOT)/usr/include/c++/4.2.1/armv6-apple-darwin10"

include $(THEOS_MAKE_PATH)/tool.mk



(11) Make and test run

cd helloworld
make clean
make
./obj/helloworld


(12) For app, the sample Makefile is
Makefile (Application) Select all

export THEOS=/var/theos
include $(THEOS)/makefiles/common.mk

APPLICATION_NAME = myapp
myapp_FILES = main.m
myapp_FILES += $(wildcard Classes/*.m)

myapp_FRAMEWORKS = UIKit

PCH:=$(wildcard *.pch)

ADDITIONAL_CFLAGS = -I"$(SYSROOT)/usr/lib/gcc/arm-apple-darwin10/4.2.1/include"
ADDITIONAL_CCFLAGS = -I"$(SYSROOT)/usr/include/c++/4.2.1"
ADDITIONAL_CCFLAGS += -I"$(SYSROOT)/usr/include/c++/4.2.1/armv6-apple-darwin10"
ifneq ($(PCH),)
ADDITIONAL_CFLAGS += -include $(PCH)
ADDITIONAL_CCFLAGS += -include $(PCH)
endif

include $(THEOS_MAKE_PATH)/application.mk

RESOURCESFOLDER=./Resources
PAYLOADFOLDER=$(THEOS_STAGING_DIR)
OBJFOLDER=./obj
INFOPLIST:=$(wildcard *Info.plist)
INFOPLIST+=$(wildcard Resources/*Info.plist)
PNGFILES:=$(wildcard Resources/*.png)
LPROJFILES:=$(wildcard Resources/*.lproj)
APPVERSION=$(shell plutil -key CFBundleVersion $(INFOPLIST) 2>&1)

# make ipa
# replace 4 spaces with TAB for below
ipa:    stage
    rm -fr $(PAYLOADFOLDER)/* $(APPLICATION_NAME)_$(APPVERSION).ipa
    rm -f Payload
    mkdir -p $(PAYLOADFOLDER)/$(APPLICATION_NAME).app
    cp $(OBJFOLDER)/$(APPLICATION_NAME) $(PAYLOADFOLDER)/$(APPLICATION_NAME).app/.
ifneq ($(PNGFILES),)
    cp -rp $(RESOURCESFOLDER)/*.png $(PAYLOADFOLDER)/$(APPLICATION_NAME).app/.
endif
ifneq ($(LPROJFILES),)
    cp -rp $(RESOURCESFOLDER)/*.lproj $(PAYLOADFOLDER)/$(APPLICATION_NAME).app/.
endif
    @echo "APPL????" > $(PAYLOADFOLDER)/$(APPLICATION_NAME).app/PkgInfo
    cp -p $(INFOPLIST) $(PAYLOADFOLDER)/$(APPLICATION_NAME).app/.
    ln -sf $(PAYLOADFOLDER) Payload
    zip -r $(APPLICATION_NAME)_$(APPVERSION).ipa Payload > /dev/null


(13) For mobilesubstrate extension, the sample Makefile is
Makefile (Tweak) Select all

export THEOS=/var/theos
include $(THEOS)/makefiles/common.mk

TWEAK_NAME = mytweak
APP_ID = com.mycompany.mytweak
mytweak_FILES = Tweak.xm
mytweak_FRAMEWORKS = UIKit

ADDITIONAL_CFLAGS = -I"$(SYSROOT)/usr/lib/gcc/arm-apple-darwin10/4.2.1/include"
ADDITIONAL_CCFLAGS = -I"$(SYSROOT)/usr/include/c++/4.2.1"
ADDITIONAL_CCFLAGS += -I"$(SYSROOT)/usr/include/c++/4.2.1/armv6-apple-darwin10"

include $(THEOS_MAKE_PATH)/tweak.mk

# make package
# replace 4 spaces with TAB for below
after-stage::
    find $(THEOS_STAGING_DIR) -iname '*.plist' -exec plutil -convert binary1 {} \;
    $(FAKEROOT) chown -R 0:80 $(THEOS_STAGING_DIR)

PACKAGEFOLDER=./layout
CONTROLFILE=control
PACKAGENAME=$(shell grep ^Package: $(CONTROLFILE) | cut -d ' ' -f 2)
PACKAGEVERSION=$(shell grep ^Version: $(CONTROLFILE) | cut -d ' ' -f 2)
ARCH=$(shell grep ^Architecture: $(CONTROLFILE) | cut -d ' ' -f 2)
OBJFOLDER=./obj
_EXCLUDES ?= tmp _MTN .git .svn .DS_Store ._*
_EXCLUDE_COMMANDLINE := $(foreach exclude,$(_EXCLUDES),--exclude "$(exclude)")


# with dpkg-deb
# replace 4 spaces with TAB for below
deb: stage
    rm -fr $(PACKAGENAME)_$(PACKAGEVERSION)_$(ARCH).deb $(PACKAGEFOLDER)/control.tar.gz $(PACKAGEFOLDER)/data.tar.gz $(PACKAGEFOLDER)/tmp
    mkdir -p $(PACKAGEFOLDER)/Library/MobileSubstrate/DynamicLibraries/
    mkdir -p $(PACKAGEFOLDER)/DEBIAN
    cp $(OBJFOLDER)/$(TWEAK_NAME).dylib $(PACKAGEFOLDER)/Library/MobileSubstrate/DynamicLibraries/.
    cp $(CONTROLFILE) $(PACKAGEFOLDER)/DEBIAN/
    dpkg-deb -b $(PACKAGEFOLDER) $(PACKAGENAME)_$(PACKAGEVERSION)_$(ARCH).deb

# without dpkg-deb
# replace 4 spaces with TAB for below
deb2: stage
    mkdir -p $(PACKAGEFOLDER)/Library/MobileSubstrate/DynamicLibraries/
    mkdir -p $(PACKAGEFOLDER)/DEBIAN
    cp $(CONTROLFILE) $(PACKAGEFOLDER)/DEBIAN/
    rm -f $(PACKAGENAME)_$(PACKAGEVERSION)_$(ARCH).deb $(PACKAGEFOLDER)/control.tar.gz $(PACKAGEFOLDER)/data.tar.gz
    rm -f $(PACKAGEFOLDER)/tmp/*.gz
    mkdir -p $(PACKAGEFOLDER)/tmp
    echo "2.0" > $(PACKAGEFOLDER)/tmp/debian-binary
    cp $(OBJFOLDER)/$(TWEAK_NAME).dylib $(PACKAGEFOLDER)/Library/MobileSubstrate/DynamicLibraries/.
    cd $(PACKAGEFOLDER)/DEBIAN; tar -czf ../tmp/control.tar.gz ./
    cd $(PACKAGEFOLDER); tar -czf ./tmp/data.tar.gz $(_EXCLUDE_COMMANDLINE) ./
    cd $(PACKAGEFOLDER)/tmp; ar -rv ../../$(PACKAGENAME)_$(PACKAGEVERSION)_$(ARCH).deb ./debian-binary ./control.tar.gz ./data.tar.gz
    rm -fr $(PACKAGEFOLDER)/tmp/*.gz


For mobilesubstrate extension, download the iPhone headers from http://github.com/rpetrich/iphoneheaders/archives/master

and place the frameworks at top level (i.e. SpringBoard folder copy to /var/theos/include/SpringBoard).
libsubstrate.dylib is also needed in /var/theos/lib folder

Note: perl is needed for creating project folder and compiling mobilesubstrate extension, if you only develop app and command line tool, you could remove perl by using

apt-get remove perl


(14) This is how to combine Tweak and Settings Bundle in a project
/var/theos/bin/nic.pl MyTweak
and choose [5.] iphone/tweak
/var/theos/bin/nic.pl MyTweakSettings
and choose [3.] iphone/preference_bundle
mv mytweaksettings/*.mm mytweaksettings/Resources mytweaksettings/entry.plist mytweak/

Makefile (Tweak + Bundle) Select all

export THEOS=/var/theos
export GO_EASY_ON_ME=1
include $(THEOS)/makefiles/common.mk

TWEAK_NAME = MyTweak
#MyTweak_FILES = MyTweak.xm
MyTweak_FRAMEWORKS = UIKit

BUNDLE_NAME = MyTweakSettings
MyTweakSettings_FILES = MyTweakSettings.mm
MyTweakSettings_INSTALL_PATH = /System/Library/PreferenceBundles
MyTweakSettings_FRAMEWORKS = UIKit
MyTweakSettings_PRIVATE_FRAMEWORKS = Preferences

ADDITIONAL_CFLAGS = -I"$(SYSROOT)/usr/lib/gcc/arm-apple-darwin10/4.2.1/include"
ADDITIONAL_CCFLAGS = -I"$(SYSROOT)/usr/include/c++/4.2.1"
ADDITIONAL_CCFLAGS += -I"$(SYSROOT)/usr/include/c++/4.2.1/armv6-apple-darwin10"

include $(THEOS_MAKE_PATH)/tweak.mk
include $(THEOS_MAKE_PATH)/bundle.mk
include $(THEOS_MAKE_PATH)/aggregate.mk

# replace 4 spaces with TAB for below
internal-stage::
    $(ECHO_NOTHING)mkdir -p $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences$(ECHO_END)
    $(ECHO_NOTHING)cp entry.plist $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences/$(BUNDLE_NAME).plist$(ECHO_END)

# replace 4 spaces with TAB for below
after-stage::
    find $(THEOS_STAGING_DIR) -iname '*.plist' -exec plutil -convert binary1 {} \;
    $(FAKEROOT) chown -R 0:80 $(THEOS_STAGING_DIR)


(15) If you want to test the iOS5 Notification Center Widget
get it from http://github.com/WillFour20/WeeAppTest

git clone git://github.com/WillFour20/WeeAppTest.git

and modified with the following Makefile

Makefile (nc Tweak) Select all

export THEOS=/var/theos
SDKVERSION = 5.0
include $(THEOS)/makefiles/common.mk

BUNDLE_NAME = WeeAppTest
WeeAppTest_FILES = WeeAppTest.mm
WeeAppTest_INSTALL_PATH = /System/Library/WeeAppPlugins/
WeeAppTest_FRAMEWORKS = UIKit CoreGraphics
#WeeAppTest_PRIVATE_FRAMEWORKS = BulletinBoard

ADDITIONAL_CFLAGS = -I"$(SYSROOT)/usr/lib/gcc/arm-apple-darwin10/4.2.1/include"
ADDITIONAL_CCFLAGS = -I"$(SYSROOT)/usr/include/c++/4.2.1"
ADDITIONAL_CCFLAGS += -I"$(SYSROOT)/usr/include/c++/4.2.1/armv6-apple-darwin10"

include $(THEOS_MAKE_PATH)/bundle.mk

# replace 4 spaces with TAB for below
after-install::
    install.exec "killall -9 SpringBoard"


and make clean package install

(15) where is IOSurfaceAPI.h in Lion ?

Here
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/IOSurface.framework/Headers/IOSurfaceAPI.h





iphone-gcc patched package for iPhone 5 / iPad 4 is here below
http://code.google.com/p/apiexplorer/downloads/list

Saturday, June 11, 2011

iCloud App Sample and entitlement code-sign error

iOS 5 beta has iCloud support now, but getting the entitlement code-sign to work has some steps that are missing from Apple Documentation.

You should use the new Xcode 4.2 for iOS 5 SDK and with iOS5 on an iDevice.

1) You need to create a new App ID in the iOS Provisional Portal, if you use an existing ID, it must not be a wildcard one. For example, you create a new APP ID called com.yourcompany.icloudtest and the App Name is called icloudtest
When you create the New App ID, you will be asked whether to Generate New or select an existing one for the Prefix (existing prefix can have the benefit of sharing the same keychain access or may be iCloud Document folder). Suppose we generate a new prefix in this case. And the new generated prefix is 99Z9Z98987

2) After created the New App ID, you should first enable iCloud for that New App ID and then create the a New Provisional Profile for that New App icloudtest.

3) Suppose the new Development Profile called "iCloudTest" is created and downloaded to the Mac.

4) Launch Xcode and created an empty Universal Application called "icloudtest" and the Bundle Identifier should be com.yourcompany.icloudtest



5) Import the Development Profile "iCloudTest.mobileprovision" to Xcode and to iPhone/iPad which should be iOS 5 beta

6) Click the Build Settings of the Project and Select the code sign identity to the "iCloudTest" Provisional Profile

7) Click the Summary Settings of the Project and scroll down to entitlements and click the Custom Entitlements, Xcode will create a file called icloudtest.entitlements


8) Click the icloudtest.entitlements in the Project Explorer and add these key rows (Right Click -> Add Row) in the entitlements file
com.apple.developer.ubiquity-kvstore-identifier is String Type
com.apple.developer.ubiquity-container-identifiers is Array Type



9) Enter the Team-ID.com.yourcompany.icloudtest into the Value column. The important part is where to get the Team-ID ?

10) Don't confuse with the Team-ID with the App ID that the development portal generated for you. If you look at the "iCloudTest.mobileprovision" file downloaded as in step 5 above. You will see something like this

Yes, ZZZZ826ZZ2 is the Team-ID where 99Z9Z989Z7 is the App ID in this case

iCloudTest.mobileprovision Select all

<key>Entitlements</key>
<dict>
<key>application-identifier</key>
<string>99Z9Z989Z7.com.yourcompany.icloudtest</string>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>ZZZZ826ZZ2.*</string>
</array>
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>ZZZZ826ZZ2.*</string>
<key>get-task-allow</key>
<true/>
<key>keychain-access-groups</key>
<array>
<string>99Z9Z989Z7.*</string>
</array>
</dict>



The Team-ID can also be found at Your Account area of Member Center
After login the iOS Dev Center, click
Member Center (in top navigation bar)-> Your Account -> Program Membership -> Individual ID



11) Enter the Team-ID + Bundle Identifier in the icloudtest.entitlements as below



icloudtest.entitlements Select all

<!--?xml version="1.0" encoding="UTF-8"?-->

<plist version="1.0">
<dict>
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>ZZZZ826ZZ2.com.yourcompany.icloudtest</string>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>ZZZZ826ZZ2.com.yourcompany.icloudtest</string>
</array>
</dict>
</plist>


12) Add these code in the icloudtestAppDelegate.m to test this iCloud App

icloudtestAppDelegate.m Select all

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

NSFileManager *fileManager = [NSFileManager defaultManager];
// Team-ID + Bundle Identifier
NSURL *iCloudURL = [fileManager URLForUbiquityContainerIdentifier:@"ZZZZ826ZZ2.com.yourcompany.icloudtest"];
NSLog(@"%@", [iCloudURL absoluteString]);

NSUbiquitousKeyValueStore *cloudStore = [NSUbiquitousKeyValueStore defaultStore];
[cloudStore setString:[iCloudURL absoluteString] forKey:@"iCloudURL"];
[cloudStore synchronize]; // Important as it stores the values you set before on iCloud

UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,round(self.window.bounds.size.height/4.0),self.window.bounds.size.width,round(self.window.bounds.size.height/8.0))];
myLabel.font = [UIFont fontWithName:@"Marker Felt" size:round(self.window.bounds.size.width/20.0)];
myLabel.numberOfLines = 4;
myLabel.text =[ @"iCloudURL=" stringByAppendingFormat:@"%@", [cloudStore stringForKey:@"iCloudURL"]];
myLabel.backgroundColor = [UIColor clearColor];
myLabel.textColor = [UIColor whiteColor];
myLabel.textAlignment = UITextAlignmentCenter;
[self.window addSubview:myLabel];

[self.window makeKeyAndVisible];
return YES;
}



13) Run it in iOS device
.
.
.

Monday, May 2, 2011

XCode 4 Template

The new Xcode 4 cannot use the old Xcode 3 templates. There are a few changes

1. Template folder location
/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates
/Users/<username>/Library/Developer/Xcode/Templates/


mkdir -p ~/Library/Developer/Xcode/Templates



2. The Templates are in folders like

iPad Base.xctemplate, iPhone Base.xctemplate, Cocoa Touch Application.xctemplate
View-based Application.xctemplate Window-based Application.xctemplate

3. The Ancestors, Definitions and Options are defined in TemplateInfo.plist

4. To add files in the Template, you should define them in Definitions like

    <key>Definitions</key>
      <dict>
        <key>___PACKAGENAMEASIDENTIFIER___MyController.h</key>
        <dict>
          <key>Group</key>
          <string>My Classes</string>
          <key>Path</key>
          <string>Classes/___PACKAGENAMEASIDENTIFIER___MyController.h</string>
        </dict>
        <key>___PACKAGENAMEASIDENTIFIER___MyController.m</key>
        <dict>
          <key>Group</key>
          <string>My Classes</string>
          <key>Path</key>
          <string>Classes/___PACKAGENAMEASIDENTIFIER___MyController.m</string>
        </dict>
        <key>README</key>
        <dict>
          <key>Path</key>
          <string>README</string>
<!-- excluded in targets -->
          <key>TargetIndices</key>
          <array/>
        </dict>
<!-- Other definitions here -->
      </dict>


Also define in Nodes

      <key>Nodes</key>
      <array>
        <string>___PACKAGENAMEASIDENTIFIER___MyController.h</string>
        <string>___PACKAGENAMEASIDENTIFIER___MyController.m</string>
        <string>README</string>
<!-- Other nodes here -->
      </array>


5. To add build stage for existing Target


    <key>Targets</key>
    <array>
      <dict>
        <key>BuildPhases</key>
        <array>
          <dict>
            <key>Class</key>
            <string>ShellScript</string>
            <key>ShellPath</key>
            <string>/bin/bash</string>
            <key>ShellScript</key>
            <string>ls -l</string>
          </dict>
        </array>
      </dict>
<!-- Other targets here -->
    </array>


6. Add New Target

    <key>Targets</key>
    <array>
<!-- Default target here -->
      <dict>
        <key>Name</key>
          <string>My Target for ___PACKAGENAME___</string>
          <key>TargetType</key>
          <string>Aggregate</string>
          <key>SharedSettings</key>
          <dict>
            <key>PRODUCT_NAME</key>
            <string>$(TARGET_NAME)</string>
          </dict>
        <key>BuildPhases</key>
        <array>
          <dict>
            <key>Class</key>
            <string>ShellScript</string>
            <key>ShellPath</key>
            <string>/bin/bash</string>
            <key>ShellScript</key>
            <string>ls -l</string>
          </dict>
        </array>
      </dict>
    </array>



For ShellScript, please use html codes like these





&lt; <
&gt; >
&amp; &





.
.
.

Sunday, May 1, 2011

Monday, April 18, 2011

My GitHub

My GitHub

http://github.com/javacom