Friday, September 21, 2012

architecture cputype (16777228) cpusubtype (0)

otool -h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/lib/crt1.o

Output is

/SDKs/iPhoneOS7.0.sdk/usr/lib/crt1.o (architecture arm64):
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
 0xfeedfacf 16777228         0  0x00          1     4        288 0x00002000

/SDKs/iPhoneOS7.0.sdk/usr/lib/crt1.o (architecture armv7):
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
 0xfeedface      12          9  0x00          1     5        532 0x00002000

/SDKs/iPhoneOS7.0.sdk/usr/lib/crt1.o (architecture armv7s):
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
 0xfeedface      12         11   0x00          1     5        532 0x00002000

/SDKs/iPhoneOS7.0.sdk/usr/lib/crt1.o (architecture armv7f):
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
 0xfeedface      12         10  0x00          1     5        532 0x00002000

/SDKs/iPhoneOS7.0.sdk/usr/lib/crt1.o (architecture armv7k):
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
 0xfeedface      12         12  0x00          1     5        532 0x00002000




grep CPU.*TYPE_ARM /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/mach/machine.h

Output is

#define CPU_ARCH_ABI64   0x01000000  /* 64 bit ABI */
#define CPU_TYPE_ARM    ((cpu_type_t) 12)
#define CPU_TYPE_ARM64  (CPU_TYPE_ARM | CPU_ARCH_ABI64)   /* 0x0100000C = 16777228 */

#define CPU_SUBTYPE_ARM_ALL   ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_ARM_V6    ((cpu_subtype_t) 6)                     /* armv6 */
#define CPU_SUBTYPE_ARM_V7    ((cpu_subtype_t) 9)              /* (armv7 */
#define CPU_SUBTYPE_ARM_V7F   ((cpu_subtype_t) 10) /* Cortex A9 */
#define CPU_SUBTYPE_ARM_V7S   ((cpu_subtype_t) 11) /* Swift */ /* armv7s */
#define CPU_SUBTYPE_ARM_V7K   ((cpu_subtype_t) 12) /* Kirkwood40 */
#define CPU_SUBTYPE_ARM_V6M   ((cpu_subtype_t) 14) /* Not meant to be run under xnu */
#define CPU_SUBTYPE_ARM_V7M   ((cpu_subtype_t) 15) /* Not meant to be run under xnu */
#define CPU_SUBTYPE_ARM_V7EM  ((cpu_subtype_t) 16) /* Not meant to be run under xnu */
#define CPU_SUBTYPE_ARM_V8    ((cpu_subtype_t) 13)

#define CPU_SUBTYPE_ARM64_ALL           ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_ARM64_V8            ((cpu_subtype_t) 1)



Sunday, June 24, 2012

How to install thoes under Xcode 4.5 (iOS 6)

(1) Installation (note : you have to install Command Line Tools (Mountain Lion) for Xcode 4.5)
if you don't have Command Line Tools use
/Applications/Xcode.app/Contents/Developer/usr/bin/git
install_theos.sh    Select all
# clone theos.git cd ~ git clone git://github.com/DHowett/theos.git # clone iphoneheaders.git cd ~/theos/ mv include include.bak git clone git://github.com/rpetrich/iphoneheaders.git include for FILE in include.bak/*.h; do mv $FILE include/; done rmdir include.bak/ # get IOSurfaceAPI.h cd ~/theos/include/IOSurface/ curl -O -k https://raw.github.com/javacom/toolchain4/master/Projects/IOSurfaceAPI.h # clone theos-nic-templates.git cd ~/theos/templates/ git clone git://github.com/orikad/theos-nic-templates.git # get dpkg-deb for Mac OS X cd ~/theos curl -OL http://test.saurik.com/francis/dpkg-deb-fat chmod a+x dpkg-deb-fat sudo mkdir -p /usr/local/bin sudo mv dpkg-deb-fat /usr/local/bin/dpkg-deb # get ldid for Mac OS X cd ~/theos/bin curl -OL http://dl.dropbox.com/u/3157793/ldid chmod a+x ldid # get libsubstrate.dylib substrate.h cd ~/theos curl -OL http://apt.saurik.com/debs/mobilesubstrate_0.9.4001_iphoneos-arm.deb dpkg-deb -x mobilesubstrate_0.9.4001_iphoneos-arm.deb mobilesubstrate cp mobilesubstrate/Library/Frameworks/CydiaSubstrate.framework/CydiaSubstrate ~/theos/lib/libsubstrate.dylib cp mobilesubstrate/Library/Frameworks/CydiaSubstrate.framework/Headers/CydiaSubstrate.h include/substrate.h


Download and untar iPhoneOS5.1.sdk.tgz to Xcode
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
tar xzvf ~/Downloads/iPhoneOS5.1.sdk.tgz


(2) get preferenceloader.git for test build
mkdir -p ~/Projects
cd ~/Projects/
git clone git://github.com/DHowett/preferenceloader.git
cd ~/Projects/preferenceloader/



(3) Modify Makefile, change from

include framework/makefiles/common.mk

to

#export TARGET=iphone:latest:2.0
export ARCHS=armv7
include $(THEOS)/makefiles/common.mk
#include framework/makefiles/common.mk


(4) Test build preferenceloader
cd ~/Projects/preferenceloader/
export THEOS=~/theos
make
make package



(5.1) Clone IconRenamer Project
#get CaptainHook headers
cd ~/theos/include/
rm -fr CaptainHook
git clone git://github.com/rpetrich/CaptainHook.git
#get and build IconRenamer
cd ~/Projects
git clone git://github.com/rpetrich/IconRenamer.git
cd ~/Projects/IconRenamer
rmdir framework; ln -sf ~/theos framework

(5.2) Modify Makefile to

export TARGET=iphone:5.1
TWEAK_NAME = IconRenamer
IconRenamer_OBJC_FILES = IconRenamer.m
IconRenamer_FRAMEWORKS = Foundation UIKit

ADDITIONAL_CFLAGS = -std=c99

include $(THEOS)/makefiles/common.mk
include $(THEOS)/makefiles/tweak.mk

(5.3) Build IconRenamer

export THEOS=~/theos
cd ~/Projects/IconRenamer
make
make package


(6) Test build UICatalog
cd ~/Projects
svn co http://apiexplorer.googlecode.com/svn/trunk/UICatalog UICatalog
cd ~/Projects/UICatalog
sed '/^SYSROOT/d' Makefile.theos > Makefile
export THEOS=~/theos
make
make ipa


Please refer to this for the updated iOS7 tweaks http://iphonedevwiki.net/index.php/Updating_extensions_for_iOS_7 .
.
.

Monday, March 5, 2012

Xcode 4.3 command line compile

In case you did't install command line tools


/Applications/Xcode.app/Contents/Developer/usr/bin/gcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -framework Foundation helloworld.m -o helloworld



git command

/Applications/Xcode.app/Contents/Developer/usr/bin/git clone git://github.com/username/project.git


This is for the latest iPhoneOS.sdk using clang

xcrun --sdk iphoneos clang -arch armv7 -framework IOKit -framework CoreFoundation -F /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks -I /Developer/Platforms/iPhoneOS.platform/DeviceSupport/Latest/Symbols/usr/include -L /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib -L /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/system -Wno-return-type -w -o vmmap vmmap.c


where is PackageMaker?

"Auxiliary tools for Xcode"

.
.
.

Monday, January 30, 2012

Darwin CC Tools odcctools_782-2_iphoneos-arm.deb

Darwin CC Tools, linker and assembler for the iOS.
v782 update
Supports armv6 and armv7

Download here http://apiexplorer.googlecode.com/files/odcctools_782-2_iphoneos-arm.deb
(odcctools_782-2 fixed the missing ld issue)
Instruction to build, see here http://github.com/javacom/toolchain4


The last build was v286 and released in 2008
.
.
.
gdb v1708 for iOS5+

Download here http://apiexplorer.googlecode.com/files/gdb_1708_iphoneos-arm.deb

.
.
.
vim with multi-byte support

Download here http://code.google.com/p/apiexplorer/downloads/detail?name=vim_7.1-4_iphoneos-arm.deb

.
.
.

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; &





.
.
.