Flipkart Search

Search This Blog

Wednesday, September 30, 2009

Core Animation for Mac OS X and the iPhone: Creating Compelling Dynamic User Interfaces

Author: Bill Dudney
Publisher: Pragmatic Programmers, LLC, The on October 15, 2008
Pages: Paperback, 182 pages
Synopsis: Mac OS X Leopard introduces a fantastic new technology that makes writing applications with animated and cinematic user interfaces much easier. We'll explore this new technology by starting with the familiar concepts you already know from the pre-Leopard development kits.

Then we'll see how they apply to the new frameworks and APIs. We'll build on your existing knowledge of Cocoa and bring you efficiently up to speed on what Core Animation is all about.

With this book in hand, you can add Core Animation to your Cocoa applications, and make stunning user interfaces that your user's will be showing off to their friends.
Get the book here

Wednesday, September 23, 2009

Run your iPhone application on both iPhone OS 2.0 and iPhone OS 3.0 and above versions

first of all in your application delegate create a varaible like this

your appdelegate header file.

float version;

then create property for accessing to another classes

@property (nonatomic, assign) float version;

in appdelegate implementation file

@synthesize version;

in this method
- (void)applicationDidFinishLaunching:(UIApplication *)application {
    version =[[[UIDevice currentDevice] systemVersion] floatValue];
    //NSLog(@"Current version no=%f",version);

now in the class where you are getting warning of method deprecations...
in header file of class
declare this

@class yourAppDelegate;

now where you declare instance variable declare your appdelegate.
    yourAppDelegate *AppDelegate;

now in implementation file of the class
import header file of your appdelegate
#import "yourAppDelegate.h"

in the viewDidLoadMethod.

- (void)viewDidLoad {
    [super viewDidLoad];
    AppDelegate=[[UIApplication sharedApplication] delegate];

 now where you are getting warning use this code.I am using temporary statements you can put your code.

if (AppDelegate.version >= 3.0)

       //put your 3.0 code here
        NSLog(@"Current OS VErsion %f",AppDelegate.version);
        [cell.textLabel setFont:[UIFont systemFontOfSize:15.0]];
        [cell.textLabel setLineBreakMode:UILineBreakModeTailTruncation];// iPhone 3.0 code here

        //put your 2.0 code here
        NSLog(@"Current OS VErsion %f",AppDelegate.version);
        [cell setFont:[UIFont systemFontOfSize:15.0]];
        [cell setLineBreakMode:UILineBreakModeTailTruncation];

use this everywhere to get rid of those warnings..

now the final part.

set active target device 3.0 debug.

change base sdk to 3.0

and change deployment target to iphone os 2.0.

note you will get warnings but don't worry it will work fine.

to check it's working run your app in any iphone which have 2.0 OS.

if you don't have iPhone with OS 3.0 check in simulator.

Saturday, September 12, 2009

Upgrading your iPhone OS 2.0 Application to 3.0 and Handle Deprecation Warnings

The warnings I was getting are as follows:
warning: ’setImage:’ is deprecated (declared at /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/
warning: ’setText:’ is deprecated (declared at /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/

//This worked perfect in OS 2.0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *UserSettingButtonCellIdentifier = @"Cell";
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:UserSettingButtonCellIdentifier];
 if (cell == nil) {
  cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier: UserSettingButtonCellIdentifier] autorelease];
     NSUInteger row = [indexPath row];
     UserSetting *rowData = [list objectAtIndex:row];
     UIImage *image = [UIImage imageNamed:@"MyImage.png"];
     if (row != 0)
         cell.image = image; //WARNING here
     cell.text = rowData.name; //WARNING here
     [rowData release];
     return cell;
//the tableView method is completely deprecated.
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
 return UITableViewCellAccessoryDisclosureIndicator;
After, doing the mods to get rid of the deprecated warnings:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 static NSString *UserSettingButtonCellIdentifier = @"Cell";
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:UserSettingButtonCellIdentifier];
 if (cell == nil) {
  cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier: UserSettingButtonCellIdentifier] autorelease];
 NSUInteger row = [indexPath row];
 UserSetting *rowData = [list objectAtIndex:row];
 UIImage *image = [UIImage imageNamed:@"MyImage.png"];
 if (row != 0)
  cell.imageView.image = image; //FIXED here
 cell.textLabel.text = rowData.name; //FIXED here
#ifdef __IPHONE_3_0
        //This is a replacement for the tableView method
 cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
 [rowData release];
 return cell;
#ifndef __IPHONE_3_0
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
 return UITableViewCellAccessoryDisclosureIndicator;

Friday, September 11, 2009

find the documents directory on the iPhone in Just One Line Code

there are quite a few ways to find the documents directory on the iPhone. For those of you who don’t know, the documents directory of an application is the location where you should save your application data. While finding the documents directory is a trivial task, it is very important when coding most applications. Apple has provided quite a few ways for resolving the path to this directory.
If you read through some of Apple’s sample code, you will see their code to do this is generally 3 or 4 lines long. This seems like a lot of code to perform such a simple task. Here is a nice one-line of code for you to use in your applications.

[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/YourDatabaseFileNameWithExtension"];

Here is the old method i was using before i found this on icodeblog.com...thanks to Brandon.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *MyDatabasePath = [documentsDirectory stringByAppendingString:@"/YourDatabaseFileNameWithExtension"];

Saturday, September 5, 2009

Installing The Application on iPhone/iPod

  1. Connect your iPhone/iPod touch to your computer.
  2. Open iTunes.
  3. Extract the included zip file. You will see a .mobileprovision file and another .ipa.
  4. Drag-and-drop the .mobileprovision file onto Library, Applications in iTunes.
    Windows Add Mobile Provision File Screenshot
  5. Double-click the .ipa(extension) file to install the application in iTunes
  6. Verify that the application shows up in Library, Applications. Note that it will have the default Apple icon.
    Windows iTunes Library Applications Screenshot
  7. In iTunes, select your Device under Devices, choose the Application tab, and make sure that the new application is checked.
    Windows iTunes Devices iPhone Applications Screenshot
  8. Sync your Device and the app should now be installed on your device.
  9. Try out the newly-installed app. 


  1. Reboot the device. Then sync.
  2. Restart iTunes
  3. Send me screen shots of any error messages you get.

Thursday, September 3, 2009

Debugging From Xcode To Real Device(Jail-Broken)

Some random iPhone stuff

Have fun ...

Using gdb to debug on the iPhone (no need for OSX)

The goal here is to debug application on real-hardware. To do that you must follow some conditions :

  • Get gdb itself

    Good news, gdb is now available on cydia. So you can install it very easily. It comes all setup with all the needed signature / entitlements to have full functionalities. If you're interested in building it yourself, you'll find the original apple sources and the needed patches / build scripts on the telesphoreo repository

    The other way (previously only way) is to grab it from the SDK. Inside the .dmg you will find a package named iPhoneHostSideTools.pkg. Inside, there is Platforms/iPhoneOS.platform/Developer/usr/libexec/gdb/gdb-arm-apple-darwin. Just copy it to the iPhone, it's a universal binary that supports armv6 just fine.
    gdb is under GNU licence so you should be free to redistribute the binary as well I think.

    For information, the original Apple source are here.

    To enhance functionality you should add some entitlements to the apple binary. Use theses : for codesign, for ldid. To apply them :

    codesign -s "iPhone developer" --entitlements gdb.xcent -f gdb-arm-apple-darwin


    ldid -Sgdb.xml gdb-arm-apple-darwin
  • Taget armv6

    Apple's modified gdb is kinda picky. It will only work properly on ARMv6 arch. ARM isn't sufficient ... You can see the different in cpusubtype in the output of otool :

    lain:iPhone tnt$ otool -h test.arm
    Mach header
    magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
    0xfeedface 12 0 0x00 2 12 860 0x00000085

    lain:iPhone tnt$ otool -h test.armv6
    Mach header
    magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
    0xfeedface 12 6 0x00 2 12 860 0x00000085

    To make sure of that you must make sure you have -arch armv6 (or -march=armv6 -mcpu=arm1176jzf-s, depending on your compiler) in you CFLAGS / LDFLAGS. Like this :

    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.0 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk test.c -o test
  • Sign the binary with entitlements

    Update: Actually if you used the entitlements I provide to sign gdb, or if you used the gdb of cydia, this step is no longer required.

    Next, you need to sign the binary you want to debug with entitlements. For details on that, see the 'Using XCode with Pwned iPhone', it's described there. I do it with codesign on OSX but ldid also support theses.

    If you're planning on doing it with ldid, the easier it to apt-get install it on your phone and do it there.

    ldid -Smyapp.xml myapp

    The myapp.xml is the XML file describing the entitlements. I generate them using a simple script but for this simple purpose you could just always use a static one that would look like this :


    Update : If you applied enhanced entitlements to gdb as described in the first point, you don't need entitlements on your binary.

Using XCode with Pwned iPhone

The idea here is to use the official SDK to create applications without having to pay for an 'official' certificate and provisioning profile.

Note that the instructions here are experimental. I can't be held responsible for whatever happens if you try them ... That being said, I can hardly imagine any issue that couldn't be solved by a DFU restore ...

Make Build & Go" + Debugging works

If you're not a fully registred / paying developer, you can use XCode to compile apps but some functions won't work. Like the 'Build & go' button, the automatic signing or the debugger. It's however possible to make them work ! Just follow the steps ...

  • Create a self-signed signing certificate

    Apple has a nice page explaining how to do that. Make sure to name your certificate 'iPhone developer'.

  • Add a custom build step to sign executables

    A pwned iPhone doesn't need a valid signature ... but it still needs one, or at least the hashes ... (for more details see on www.saurik.com). Jay Freeman made a small utility called ldid that add thoses hashes. However here we will use the official codesign utility, provided by Apple, with our self-signed identity.

    To make remote debugging work, we also need to add entitlements to the Application. This will be handled by codesign as well. We will however need a small python utility gen_entitlements.py to generate the entitlement file. Download it, place it somewhere on your disk and make it executable.

    So, to execute codesign properly during the build, you will need to add a custom build step to each of your XCode projects. Select the menu options "Project > New Build Phase > New Run Script Build Phase", and enter the following script (don't forget to replace /Users/youruser/bin by the correct path to gen_entitlements.py) :

    export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
    if [ "${PLATFORM_NAME}" == "iphoneos" ]; then
    /Users/youruser/bin/gen_entitlements.py "my.company.${PROJECT_NAME}" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent";
    codesign -f -s "iPhone developer" --resource-rules "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/ResourceRules.plist" \
  • Remove signature checks from MobileInstallation & SpringBoard

    The final step is to bypass some security checks in some executable. The idea is simple to patch them, using a small software. Of course, after patching, you need to re-generate a signature for the new binaries to get loaded properly. All-in-all, it's easier to do all that on your Mac. So open a console and cut & paste the instructions (I assume you have ssh on the iPhone and that it's IP is :

    The binary patch has been written for 2.0.0 and I didn't get a change to test/update it to 2.0.1 ... so make sure you have a backup of the files and an active ssh if needed

    osx:~ user$
    osx:~ user$
    osx:~ user$
    osx:~ user$
    osx:~ user$
    osx:~ user$
    osx:~ user$
    osx:~ user$
    osx:~ user$
    osx:~ user$
    osx:~ user$
    osx:~ user$
    osx:~ user$
    osx:~ user$
    osx:~ user$
    mkdir iphone_tmp
    cd iphone_tmp
    scp root@ .
    scp root@ .
    cp MobileInstallation MobileInstallation.bak
    cp SpringBoard SpringBoard.bak
    curl -O http://www.246tNt.com/iPhone/iphone_binary_patch
    curl -O http://www.246tNt.com/iPhone/SpringBoard.xcent
    chmod +x ./iphone_binary_patch
    export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
    codesign -s "iPhone developer" -f MobileInstallation
    codesign -s "iPhone developer" --entitlements SpringBoard.xcent -f SpringBoard
    scp MobileInstallation root@
    scp SpringBoard root@

    Finally, reboot the phone ... and enjoy :) Note that you may have to restart XCode and re-plug the iPhone for the connection to work. Also, if you had done previous attempts without following this how-to, you might need to clear the /var/mobile/Media/PublicStaging directory on the iPhone.

source taken from:--http://www.246tnt.com/iPhone/#xcode