AppDelegate difference between Xcode 3 and Xcode 4.3.1 - iphone

I just started learning to write iPhone app (maybe a little too late) from a book I picked up from the library "Beginning iPhone Games Development" published by APress. I now come to believe it's written for XCode 3. But at this time, XCode 4.3.1 with iOS 5 SDK is what I can download.
The book lists a code block:
// XCODE 3: changing to landscape orientation in AppDelegate.m
- (void) applicationDidFinishLaunching:(UIApplication*)application {
[application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[application setStatusBarHidden:YES animated:NO];
[window addSubView:viewController.view];
[window makeKeyAndVisible];
}
After quite some struggle, I conclude that there are significant changes between the two XCode versions as it did not mention any changes that needs to be done to AppDelegate.h or connecting view/controller IBOutlets.
Can anyone please show me a good reference about the changes as well as what could be the same code in Xcode 4.3.1?

From a single view application created by template in Xcode 4.3.2:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Many things changed, not only from iOS 3 to iOS 5, but also from Xcode 3 to Xcode 4. You may find it a bit hard to refer to books written for Xcode 3 when you are using Xcode 4.
P.S. There is a new book Beginning iOS 5 Games Development from Apress, but I don't have any comments since I haven't read it.

Related

App wont start using testflight on iOS6

I have an application that I want to test it on iOS device. The application uses NIB files and no story board.
Target framework is set to - 5.1
Device - Universal.
I have created the IPA file and uploaded to TestFlightApp.
I have downloaded and installed the application on my iPad. Weird thing is when I tap on the icon a black screen shows and nothing else happens.
I have done the following settings.
Main Interface - SSDMainViewController
Main Storyboard - Not set as I don't have any storyboard in the applicaion.
It is not the problem of IOS versions as other apps are working fine.
EDIT : When I double click the iPad button I saw that the application
is not crashing. It is running in the background.
EDIT 2 : More information on the question.
Well I have taken a view based application and it has all NIBs no storyboard. It was initially an iPhone application targeting the IOS 5.1 but then I have changed the value from the project drop down to UNIVERSAL. But that I think is no problem because when I installed it in my iPad it showed me nothing. Also it showed black screen with the iPhone frame and then nothing. The application is still live in the thread.
What bothers me is that I have done this in the AppDelegate :
I have set the
self.mainViewController = [[SSDMainViewController alloc] initwithnibname:#"SSDMainViewController" bundle:nil];
And then I have set the navigation controller and then pushed the view to it.
I FOUND SOME MORE INFORMATION
In the console it says.
The application is expected to have its root view set at the end of application start.
MY APP DELEGATE
ftipValue=0.25;
cardtype = #"American Express";
[cardtype retain];
[self CallFunctionForLogout];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Create an instance of YourViewController
//SSDMainViewController *yourViewController = [[SSDMainViewController alloc] init];
self.mainViewController = [[[SSDMainViewController alloc] initWithNibName:#"SSDMainViewController" bundle:nil] autorelease];
// Create an instance of a UINavigationController
// its stack contains only yourViewController
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:self.mainViewController];
navController.navigationBarHidden = YES;
// Place navigation controller's view in the window hierarchy
[[self window] setRootViewController:navController];
[self.window makeKeyAndVisible];
return YES;
Please use two xib file, universal app we want two xib (nib)
one for iPhone - ViewController_iPhone
second for for iPad - ViewController_iPad
Add following code to your AppDelegate.m file.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil] autorelease];
}
else {
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil] autorelease];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
I have done this and it's work fine for me.
That error means that you're not setting up your application correctly.
You say you've set SSDMainController as the main interface file - is this both for iPhone and iPad? There are two sets of entries in that section of the summary tab for universal apps.
I would expect a different xib file to be specified for the iPad, since a different sized view and different layout would be in use.
You have either not set the iPad xib, so the app can't set up a window with root view controller, or you haven't set up a valid iPad xib, so it isn't loading at all, with the same results.
If you just want the app to run in the mini-iPhone window with the 2x button, leave it as an iPhone only app.
If you are getting "The application is expected to have its root view set at the end of application start." there are a number of possibilities. Clearly, that is the problem, since you have a black screen with nothing in it...
Check out this SO question: Application windows are expected to have a root view controller at the end of application launch warning Rob Mayoff has a good description of what should be happening when your application initializes.
Also, linked to in the above post, is this post wherein there are an additional 35 answers with various scenarios of what could be happening.
Beyond browsing through those links, you will need to post up additional code and/or descriptions of how your nibs are wired up for anyone to help you--as evidenced by the myriad ways it is possible to cripple the initialization sequence.

UINavigationController in iOS 5.1

I am new in Objective-C and iOS. I followed UINavigationController.
In the first 2:30min off the video, He uses AppDelegate interface and implementation and There are some codes provided there which I don't have in my application.
In the interface he has:
#Class ViewController;
...
#property(strong, nonatomic) ViewController *viewController;
which I don't have.
And in the implementation of AppDelegate, before he start to define navigationViewController, he has some lines of codes in didFinishLaunchingWithOption like:
self.windows = [[UIWindows alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.windows.rootViewController = self.viewController;
[self.windows makeKeyAndVisible]
return YES;
I got warning on self.viewController.
but I just have:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
To nix the NavigationViewController, he adds this line:
UINavigationController *navigationViewController = [[UINavigationController alloc] initWithRootViewController:self.viewController
self.windows.rootViewController = navigationViewController;
When I added this code I faced an error (warning on self.viewController at the end).
When I run the project, it just show the navigation at the top, but the TableView that I created before, is disappeared.
Can you help me how can I fix this problem? My simulator is version 5.1.
I am assuming since this is Part 12 of his youtube series, he is building off previous code.
Regardless, there are many ways to add the rootViewController to the window. (programmatically, via Storyboards, etc.)
The simplest way to get a project setup which would match his tutorial would be:
Create a new "Single View" Project in Xcode and DO NOT enable Storyboards.
This will create a project with an AppDelegate, ViewController class and ViewController xib.
(If you selected Universal app you will have 2 xib files)
Open up the AppDelegate for this newly created project and it should very close to his screencast...
Good luck!
(note this was verified with XCode 4.3.3)

Make an iPad app from an existing iPhone app?

If I wanted to make an iPad app from an existing iPhone app that I have released, would I have to create a new project targeted for iPad and create a new app ID and provisioning profile etc, and if so can the app have the same name? Or, do I create it within the existing iPhone targeted project.
Apologies if this question isn't technical enough for this forum...
Thanks.
You can create it within the existing iPhone project. Keep the same app ID. Apple will be delighted that you've gone universal. :) I'm assuming here that you mean to go universal. If you mean two separate apps, one for iPhone and one for iPad, that's two different apps; you can share code by using the same project, but they will have different targets and different IDs.
If you don't want to drag all your files over to a new project, i recommend the following:
In your build settings, deployment change the targeted device family to iPad / iPhone from iPhone.
Then for xib files you want to add you iPhone and iPad nib file to the project and an if statement calling the specified nib... I recommend just creating a simple view based project (that is Universal) and then looking at the code... You will see something like this.
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil] autorelease];
} else {
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil] autorelease];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
You might have to add some supported orientations in you App-Info.plist for the iPad too.
More information can be found here in the section about Universal apps:
http://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/iPhoneAppProgrammingGuide.pdf
E.

Building to iPod Touch 3.1.3 in Xcode 4

When trying to build my project to my iPod touch 1st gen 3.1.3, the project builds, and it put on my ipod, but then at launch it throws an NSExeption, and gives a SIGABRT at the line self.window.rootViewController = self.viewController;
in my app delegate. The deployment target is all right at 3.0, and the SDK is 4.2. It builds to my iPad running 4.2 fine. What is the problem here?
SOLVED: replace "self.window.rootViewController = self.viewController;" with "[self.window addSubview:_viewController.view];"
#implementation Physics_ProjectAppDelegate
#synthesize window=_window;
#synthesize viewController=_viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:_viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
According to documentation, [UIWindow rootViewController] is
"Available in iOS 4.0 and later." and that is why your app crashes on the actual device which is is 3.1.3 as you say.

App shows white screen on startup after upgrading to iOS 4.2

For the past few weeks I have been working on an app that uses a SoundManager class that I found via the comments of this blog post:
http://www.gehacktes.net/2009/03/iphone-programming-part-6-multiple-sounds-with-openal/
The link to the SoundManager and tester app is provided in the comments by David Evans. I am not allowed to provide a second link so I'll mention the name of ZIP file he links to:
SoundTester.zip
I was very happy with this code, until iOS 4.2 was released. After updating my iPad and Xcode correspondingly, my apps that use the SoundManager class only show the navigation bar with it's title. The rest of the screen is white. It's not iPad specific behavior. I have seen the same on an iPhone4 and an iPhone 3G that upgraded to iOS 4.2.
When running the apps in the simulator, I get the same results. The problem is that I get no error messages in the console window and no build and compile errors at all. Very frustrating and very hard to fix for an iPhone developer that started using the iPhone SDK only months ago.
Does anyone have a clue what could have gone broken and how to fix it? Any help is appreciated!
Somebody please shoot me...
Just found the problem, with the help from a piece of code I had written down from the iPhone Developer's Cookbook.
The problem was not the SoundManager (which still works fine, fortunately!) but in the application:didFinishLaunchingWithOptions: method in the App Delegate class.
Here is the code that causes the problem in iOS 4.2 but still works in iOS 3.2:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Create a Navigation Controller on the fly.
// Use the View Controller as root view controller.
viewController.title = #"ThreeSounds";
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
nav.navigationBar.barStyle = UIBarStyleBlack;
// Add the view controller's view to the window and display.
[window addSubview:nav.view];
[nav release];
[window makeKeyAndVisible];
return YES;
}
The solution: remove the line that says: [nav release].
For some reason, releasing the navigation controller was not a problem in iOS 3.2.
In iOS 4.2 is makes the screen go white.
I found out that this method was the problem because it was the last method that was executed. That, in turn, I found out by adding this piece of code to every class in my project:
-(BOOL) respondsToSelector:(SEL)aSelector {
printf("SELECTOR: %s\n", [NSStringFromSelector(aSelector) UTF8String]);
return [super respondsToSelector:aSelector];
}
This piece of code logs all the methods that get called.
I used the following code in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if (!window)
{
[self release];
return 0;
}
This method caused white screen when I launched my app. It was OK in 3.2 / 4.0 SDK. In SDK 4.3 it is causing the problem. Just comment or remove this code if you have it.
I had same problem. The problem was duplicated UIWindow.