Posts Tagged ‘ios’

XCode Hangs when Attaching to App

Wednesday, January 25th, 2012

XCode 4 would hang while attaching to my iOS app. After some research and trial and error, I eventually resolved the problem. There appears to be a number of different causes and solutions to the problem. In my case, the problem was caused by a folder reference (blue folder) under the Supporting Files. Deleting the folder reference and then adding it back solved the problem.

How to Upgrade to iOS 5

Thursday, October 13th, 2011

Posted some instructions on how to upgrade to iOS 5 here

UIBarButtonItem – Programmatically

Wednesday, October 12th, 2011

There is a great tutorial on how to programmatically create and customized the UINavigationController (including UIBarButtonItem) here.

One issue I had was while Adding items to the right of your Navigation Bar. A bar button item is created like so:


UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle@"My Button" style:UIBarButtonItemStyleBordered target:self action:@selector(doSomething)];
self.navigationItem.rightBarButtonItem = myButton;
[myButton release];

The doSomething above, is a method and it looks like this:


- (IBAction)doSomething:(id)sender
{
NSLog(@"%@", @"My Button was pressed");
}

You might expect this to work, however, when the button is pressed the program will crash with an unrecognized selector error. This is because the signature of the doSomething method has a colon on the end of it: doSomething:

Therefore, the code for creating the UIBarButtonItem should be:


UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle@"My Button" style:UIBarButtonItemStyleBordered target:self action:@selector(doSomething:)];
self.navigationItem.rightBarButtonItem = myButton;
[myButton release];

Custom iOS UIViewController (Universal)

Wednesday, September 7th, 2011

These are the steps to create a custom UIViewControllers and .XIB files that take the place of the default MainWindow_iPhone.xib and MainWindow_iPad.xib in a Universal application.

Below is the architecture diagram. A custom HelloUniverseViewController will inherit from UIViewController. HelloUniverseViewController will not have a .XIB file. HelloUniverseViewController_iPhone and HelloUniverseViewController_iPad inherit from HelloUniverseViewController and have .XIB files. Functionality that is common between the two devices should be implemented in HelloUniverseViewController. Device-specific functionality should be implemented in the appropriate iPhone or iPad view controller.

Class Diagram

1. Create a new Window-based Application.
– Device Family = Universal

2. In the HelloUniverse folder, add a new UIViewController subclass.
– UNCHECK “Targeted for iPad”
– UNCHECK “With XIB for user interface”
– Save As “HelloUniverseViewController”

3. Edit HelloUniverseAppDelegate.h. Add the bold lines below.

#import <UIKit/UIKit.h>

@class HelloUniverseViewController;

@interface HelloAppDelegate : NSObject <UIApplicationDelegate]]]]>

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet HelloUniverseViewController *viewController;

@end

4. Edit HelloUniverseAppDelegate.m. Add the bold lines below.

#import "HelloUniverseViewController.h"

@synthesize window = _window;
@synthesize viewController = _viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    self.window.rootViewController = self.viewController;

    [self.windowmakeKeyAndVisible];
    return YES;
}

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

iPhone

5. In the iPhone folder, add a new UIViewController subclass.
– Subclass of HelloUniverseViewController
– UNCHECK “Targeted for iPad”
– CHECK “With XIB for user interface”
– Save As “HelloUniverseViewController_iPhone”

6. In the iPhone folder, open MainWindow_iPhone.xib.

7. From the Objects list, drag a View Controller object onto the bar.

Object List

|
|
V

Bar

8. Select newly added View Controller object.

UIViewController button

9. Go to the Identity Inspector and change the Class to HelloUniverseViewController_iPhone.

10. Go to the Connections Inspector and add a New Referencing Outlet, viewController = App Delegate

11. Add a label to the HelloUniverseViewController_iPhone.xib: “Hello Universe iPhone”

iPAD

12. In the iPad folder, add a new UIViewController subclass.
– Subclass of HelloUniverseViewController
– CHECK “Targeted for iPad”
– CHECK “With XIB for user interface”
– Save As “HelloUniverseViewController_iPad”

13. In the iPad folder, open MainWindow_iPad.xib.

14. From the Objects list, drag a View Controller object onto the bar.

Object List

|
|
V

Bar

15. Select newly added View Controller object.

UIViewController button

16. Go to the Identity Inspector and change the Class to HelloUniverseViewController_iPad.

17. Go to the Connections Inspector and add a New Referencing Outlet, viewController = Hello Universe App Delegate i Pad

18. Add a label to the HelloUniverseViewController_iPhone.xib: “Hello Universe iPhone”

19. Save, Build and Run

Click here to download the sample XCode project. It targets iOS 4.3 for the iPhone and iPad.

Custom iOS UIViewController

Wednesday, September 7th, 2011

These are the steps to create a custom UIViewController and .XIB that take the place of the default MainWindow.xib.

1. Create a new Window-based Application.

2. Add a new UIViewController subclass.
– CHECK “With XIB for user interface”
– Save As “HelloViewController”

3. Edit HelloAppDelegate.h. Add the bold lines below.

#import <UIKit/UIKit.h>

@class HelloViewController;

@interface HelloAppDelegate : NSObject <UIApplicationDelegate]]>

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet HelloViewController *viewController;

@end

4. Edit HelloAppDelegate.m. Add the bold lines below.

#import "HelloViewController.h"

@synthesize window = _window;
@synthesize viewController = _viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    self.window.rootViewController = self.viewController;

    [self.windowmakeKeyAndVisible];
    return YES;
}

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

5. Open MainWindow.xib.

6. From the Objects list, drag a View Controller object onto the bar.

Object List

|
|
V

Bar

7. Select newly added View Controller object.

UIViewController button

8. Go to the Identity Inspector and change the Class to HelloViewController.

9. Go to the Connections Inspector and add a New Referencing Outlet, viewController = Hello App Delegate

10. Add a label to the HelloViewController.xib: “Hello World!”

11. Save, Build and Run

Click here to download the sample XCode project. It targets iOS 4.3 for the iPad.

Submitting iOS App to App Store

Monday, August 22nd, 2011

After completing all the forms in iTunes Connect, you will need to upload your app to the App Store. The app can be uploaded using the Organizer in XCode 4.

If you have not already done so, you will need to download and install a Distribution Provisioning Profile. Log into the Member Center on http://developer.apple.com and then go to the iOS Provisioning Portal. Then go to the Provisioning page and click on the Distribution tab. Then create a New Profile for your app. Once it’s created, download and install the profile. The profile can be installed by clicking on the downloaded .mobi file.

Next, make sure the XCode project is using the Distribution profile for code signing. First, go to your project’s Build Settings as show in the image below:

XCode Build Settings

Then, under the Code Signing section, change the Release and Any iOS SDK settings to the Distribution profile you downloaded/installed:

XCode Code Signing

Now, the project needs to be Archived. First, change the Active Configuration to the iOS Device. In my case, it is the iPad named Playa:

XCode Active Configuration

Then go to Product -> Archive. This will create an archive package of the app that can be uploaded to the App Store. When the archiving process is complete, it should open the Organizer. If it does not, the Organizer can be accessed from Window -> Organizer.

With the Organizer window open and your app selected, click the Validate button. Enter your Apple Developer credentials and make sure you choose the correct Distribution profile (it should match the one selected in the Project Build Settings). If all is good, the validation process will be successful and you can proceed to submitting the app.

If there are no errors in the validation process, then you can submit the app. With the Organizer window open and your app selected, click the Submit button. Again, enter your Apple Developer credentials and make sure you choose the correct Distribution profile. Once, the submit process is complete, you will get a message saying so.

Note: If you make any code or project changes, remember to re-create the archive.