Installing iPhone firmware 2.1

September 14th, 2008 Arash

Here’s a step by step on how to install the new 2.1 firmware using PwnageTool. I’m assuming that you’ve alread Pwned your phone before when you follow this tutorial. If you haven’t, the steps at the end may be a little different for you.

  1. Update to iTunes 8 and restart
  2. After the reboot, plug in your phone, then open up iTunes. It will ask if you want to update your phone. Click ‘Download only’. If you accidentally clicked cancel, just click on your phone in the iTunes sidebar, then click ‘Update’ to get the latest firmware. Then once the download starts, unplug your iPhone from the USB port.
  3. Once the download finishes, close iTunes
  4. Open up the ‘Activity Monitor’ app from /Applications/Utilities. Find the ‘iTunes Helper’ in the list of running programs and kill it (the red button at the top left).
  5. Set your phone’s auto-lock to never (Settings->General->Auto Lock->Never)
  6. After downloading PwnageTool and copying it to your /Applications folder, launch the program.
  7. Select your device (I’m using the original iPhone) and click the next arrow.
  8. PwnageTool will search for the ipsw firmware file you just downloaded (and it should find it). Select it and click the next arrow.
  9. Now PwnageTool will look for the bootloader v4.6 and 3.9 files. If you don’t have them, you can download them here. After downloading the files, click ‘No’ to searching the web for the bootloader file. At the next dialog, click ‘Yes’ to browse for the location where you downloaded the file.
  10. Now PwnageTool will ask you if you have an iPhone contract that would normally activate through iTunes. If you are using the Apple approved carrier in your country, you can click ‘Yes’, and this will skip the unlocking process on your phone. Just say ‘No’ if you want your phone unlocked.
  11. Now PwnageTool will build an ipsw file for your phone.
  12. After the file is created, close PwnageTool, disconnect and turn off your phone, and open up iTunes.
  13. Now we need to put the phone into recovery mode. While the phone is off, hold down the ‘Home’ button, and at the same time plug your phone into your Mac. Keep holding down the ‘Home’ button until iTunes tells you that your phone is in recovery mode and needs to be restored.
  14. In iTunes, hold down the option key and click ‘Restore.’ Select the new firmware file that PwnageTool just created, and you should be good to go in about 10 minutes.
  15. Enjoy your updated phone!

Posted in Tutorials, iPhone | 3 Comments » |    Add to Mixx!

Open links from UIWebView in MobileSafari

September 6th, 2008 Arash

If you’ve embedded a UIWebView in your iPhone/iPod app, you may not want the user to suffer through surfing all successive pages through it. Instead, you can open up your first page inside a UIWebView and any links the user tries to follow will instead open up in MobileSafari.

All you need to do is set the UIWebView’s delegate, to an object that implements the optional method webView:shouldStartLoadWithRequest:navigationType: (part of the UIWebViewDelegate protocol). Then whenever the initial page is loaded or a link is followed in that view, the delegate’s method will be called. You’ll want to return YES for the page you initially load, and then return NO for all others, and open the URL in MobileSafari. Here’s what the method implementation should look like:

- (BOOL)webView:(UIWebView *)webView
    shouldStartLoadWithRequest:(NSURLRequest *)request
    navigationType:(UIWebViewNavigationType)navigationType
{
    if ([[[request URL] absoluteString] isEqual:@"http://arashpayan.com/myInitialPage/"])
        return YES;
    
    [[UIApplication sharedApplication] openURL:[request URL]];
    
    return NO;
}

By returning NO from the delegate method, we’re telling the web view not to load the link the user tapped, but instead we redirect the opening of the link to [UIApplication openURL:] (MobileSafari).

Posted in Tutorials, iPhone | No Comments » |    Add to Mixx!

Change iPhone/iPod app orientation within a UITabBarController

September 4th, 2008 Arash

The documentation for the official iPhone SDK is less than stellar, and as a result I’ve encountered lots of frustrating little problems. In particular, I wasn’t able to get my app to change its orientation when the phone was rotated. UIViewController has a method shouldAutorotateToInterfaceOrientation: that gets called when the iPhone/iPod orientation is changed by the user, and overriding this method to return YES should cause your view to be rotated. You may have implemented this method and to your frustration, nothing happened when you rotated the device. The trick is that Cocoa only calls shouldAutorotateToInterfaceOrientation: on the top most UIViewController. Meaning if your program lives inside a UITabBarController (possibly with a UINavigationController inside some of the tab bar items), the UIViewController that the user is currently interacting with, is not necessarily the one receiving the method call.

In my app, everything lives inside a UITabBarController, so that’s what was receiving the shouldAutorotateToInterfaceOrientation: call. In order to get orientation changes to work you need to subclass UITabBarController (contrary to Apple doc recommendations) and override the method so you can return YES when it’s called. Below is some code for a simple UITabBarController subclass used inside a program that supports a horizontal view.

RotatingTabBarAppDelegate.h

#import <UIKit/UIKit.h>

#import "RotatingTabBarController.h"

/*
 Nothing special implemented in our delegate for this example.
 */

@class RotatingTabBarAppViewController;

@interface RotatingTabBarAppAppDelegate : NSObject <UIApplicationDelegate> {
    IBOutlet UIWindow *window;
}

@property (nonatomic, retain) UIWindow *window;

@end

RotatingTabBarAppDelegate.m

#import "RotatingTabBarAppAppDelegate.h"

@implementation RotatingTabBarAppAppDelegate

@synthesize window;

/*
 We’ll programmatically lay out a simple GUI for this demonstration.
 */

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    
    // Just make two empty view controllers for fun
    UIViewController *tab1 = [[UIViewController alloc] init];
    tab1.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemTopRated tag:0];

    UIViewController *tab2 = [[UIViewController alloc] init];
    tab2.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1];
    
    // Now create an instance of our rotating tab bar controller
    RotatingTabBarController *tbc = [[RotatingTabBarController alloc] init];
    // Add the two view controllers to the tab bar
    [tbc setViewControllers:[NSArray arrayWithObjects:tab1, tab2, nil]];
    
    // Add the tab bar controller’s view to the window
    [window addSubview:tbc.view];
    
    // Make our program visible
    [window makeKeyAndVisible];
}

- (void)dealloc {
    [window release];
    [super dealloc];
}

@end

RotatingTabBarController.h

#import <UIKit/UIKit.h>

/*
 The subclass doesn’t need any new methods or members.
 */

@interface RotatingTabBarController : UITabBarController {

}

@end

RotatingTabBarController.m

#import "RotatingTabBarController.h"

@implementation RotatingTabBarController

/*
 Just override this single method to return YES when we want it to.
 */

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Always returning YES means the view will rotate to accomodate any orientation.
    return YES;
}

@end

The one thing this doesn’t address, is when you only want certain views in your program to rotate. In that case you just need to make your UITabBarController ask the currently visible view controller in the program if the app should rotate, and return that BOOL.

Posted in Tutorials, iPhone | 5 Comments » |    Add to Mixx!