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.
Related
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 works fine on iPhone device, iPhone simulator but when tested on iPad simulator it crashed and message got is
[UIWindowLayer convertPoint:fromView:]: unrecognized selector sent to instance.
Program received signal EXC_BAD_ACCESS on thread1 UIApplicationMain
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
self.containerViewController = [[[ContainerViewController alloc]init]autorelease];
self.window.rootViewController = self.containerViewController;
[window makeKeyAndVisible];
return YES;
}
Is there something wrong in UIApplication in app delegate or i have change some setting in info.
Any idea why it is crashing only on iPad simulator when running fine on iPhone device, iPhone simulator.
Any clue how to fix this issue.
Thanks for help.
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.
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).
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.