Xcode 4 iphone 3.1.3 applications not work - iphone

i'm working with Xcode 4 and my software work well on iPhone 4 and simulator but when i test it on devices like iPhone 2G or 3Gs i have this error immediately when i run the code :
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key rootViewController.'
searching the way to solve the problem i build a hello world program and do not work on iPhone 3gs ... searching the solutions i found this :
// self.window.rootViewController = self.viewController;
[self.window addSubview: [self.viewController view]];
use addsubview like this and the program should run fine ...
Ok the hello world run well but my program does not work at all ...
maybe this is the code i should change ... (but i don't now really ..)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//this and application should run on 3.1.3
if ([self.window respondsToSelector:#selector(setRootViewController:)])
self.window.rootViewController = self.viewController;
else
[self.window addSubview:self.viewController.view];
// Add registration for remote notifications
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
// Clear application badge when app launches
//application.applicationIconBadgeNumber = 0;
[self.window makeKeyAndVisible];
return YES;
}
i search some info about this problem but every time i search i found only to change the line
self.window.rootViewController = self.viewController;
but unfortunately don't help much.
thanks guys for you're patience :)
EDIT :
i change the code
if ([self.window respondsToSelector:#selector(setRootViewController:)])
self.window.rootViewController = self.viewController;
else
[self.window addSubview:self.viewController.view];
to
[self.window addSubview:self.viewController.view];
but the error is still the same ...

UIWindow does not have a rootViewController property in iOS versions less than 4.0. Hence if you want to support these versions, you can't use self.window.rootViewController = myViewController;, you generally have to add the controller's view to the window, i.e.: [self.window addSubview:myViewController.view];
Edit: the problem is how you are checking for what version it is, since 3.1.3 could have still responded to setRootViewController (built in but not public variable).

Related

phonegap iphone app showing black screen on iPad

I am developing and testing my iphone app (phonegap + native) properly on iPhone simulator and device.
However, when testing on iPad simulator or device, I can only see a blank black screen and no errors on console.
Target family is properly set to iPhone and window makeKeyAndVisible also executed! How to solve it?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *introVC = [[videoViewController alloc] initWithNibName:#"videoViewController" bundle:nil];
UIViewController *blogVC = [[blogViewController alloc] initWithNibName:#"blogViewController" bundle:nil];
NSArray *viewControllers = [NSArray alloc];
viewControllers = [NSArray arrayWithObjects: introVC, blogVC, nil];
[rootController setViewControllers:viewControllers animated:NO];
self.rootController.selectedIndex = 0;
[window setRootViewController:self.rootController];
[window makeKeyAndVisible];
return YES;
}
A black screen is pretty much always an error in the javascript. Assuming you are using iOS 6 you should be able to attach the desktop safari web inspector and look for any javascript errors, which will not show up in the Xcode console.
Another thing to test is that the app still works as a clean install on iPhone - updating an existing app only copies new and updated files, so errors caused by deletion such as renaming a script and leaving a reference to the old filename won't show up right away.

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.

AppDelegate difference between Xcode 3 and Xcode 4.3.1

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.

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.