Error occurred in appDelegate method - iphone

Error occurred in appDelegate.m file while i run the sample signal aborted at
self.view.controller=root.view.controller
please help me i added code below
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/* bad signal occurred at this line */
self.window.rootViewController=self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
thanks

The UIWindow rootViewController property doesn't exist before iOS4. If you're trying to run this code on an device with iOS 3 or older, it will crash.
In your AppDelegate, you can use addSubview instead.
//self.window.rootViewController = self.viewController; // Only iOS >= 4
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
return YES;
Hope this helps.

Your syntax for self.view.controller = root.view.controller is a bit weird. I think you mean self.viewController = rootViewController ? Even so, that is incorrect.
Try something like -
self.viewController = [[YourViewController alloc]init];
self.window.rootViewController = self.viewController;
Replace YourViewController with the class of your controller.

Related

App crashes on [TestFlight takeOff:#""] in iOS 6.1.2

I have TestFlight SDK integrated into my iOS app. In iOS 6.1.2, sometimes the app crashes for the first-time app launch at TestFlight's -takeOff: method.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
#ifdef TESTING
[TestFlight takeOff:#"MY_TESTFLIGHT_TEAM_TOKEN"];
[TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]];
#endif
// Override point for customization after application launch.
ProductListViewController *products=[[ProductListViewController alloc] initWithNibName:#"ProductListViewController" bundle:nil];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:products];
[products release];
navigationController.toolbarHidden = YES;
navigationController.navigationBarHidden = YES;
self.rootViewController = navigationController;
[self.window setRootViewController:rootViewController];
[navigationController release];
[self.window makeKeyAndVisible];
return YES;
}
Any help is greatly appreciated.
Thanks
This is a bug in the Testflight SDK. They ask you to update to the latest beta version.
See iOS exception EXC_GUARD
Could it be that you've forgotten to include the TestFlight SDK folder properly?

iPad simulator just shows black screen

I am developing an app in Xcode, I got it working and was putting some finishing touches.
Then I upgraded Xcode to the latest version, changed a bit the code for the Autorotate options (my app shouldn't autorotate) and fiddled with the supported rotation (landscape vs. portait).
Then suddenly my debug in iOs simulator just shows a black screen. The app builds fine but nothing is shown in the simulator....
And I can't really understand why...
Using Xcode 4.6
i don't have an ApplicationDidFinishLoading but I have this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES; }
Use Below Code instead in your ApplicationDidFinishLoading
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[YourFirstViewController alloc] initWithNibName:#"YourFirstViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
This may solve your problem. Please try it.
commenting the "shouldAutorotateToInterfaceOrientation" solved my problem.

Restart application after low memory warning

I'm using my appDelegate's applicationDidReceiveMemoryWarning method to dump some high resource objects. When the app starts back up, rather than trying to reload just those objects and return the user to his last page, I would like just to restart the app from the top (from the main page, the app only goes one level deep, so this is totally acceptable to us).
Here's my paltry attempt, but it was an abject failure. It got close, but I ended up introducing some problems that resulted in an actual memory dump and app crash.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[SplashScreenViewController alloc] initWithNibName:#"SplashScreenViewController" bundle:nil];
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navcon;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
//For testing purposes only
self.lowMemoryWarning = TRUE;
NSLog(#"app did enter background");
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(#"app will enter foreground");
if (self.lowMemoryWarning) {
NSLog(#"recovering from low memory warning");
self.window.rootViewController = nil;
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navcon;
[self.window makeKeyAndVisible];
}
}
What's the best approach for doing something like this? Is there maybe a simple trick that I don't know about?
Thank you!
Do you mean you want the app to restart each time it started (or enter foreground) ? If yes, maybe you can just set the app to not support multi tasking
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW5
Search for "Opting out of Background Execution"
================================================================================
Ah sorry, I didn't know the nature of your application, if some process need to be run on the background then this method is no go.
I read your comment above about the UIActivityIndicator + loading the certain objects back on the current view after app enter foreground. Maybe this thread can help you, Finding the current view when application enter foreground. IOS

Converted to ARC App crashes on any method iPhone

I converted my app to ARC and removed all the pre-build release errors. It launches, but will crash (EXC_BAD_ACCESS) as soon as I call any method (all of which are attached to UIButtons). I also noticed that it will ask if the user will allow for the app to use the user's location, but the alert will disappear before the user can answer yes or no.
I feel like there's some very basic setting I'm missing causing this.
Here's the first method called, it won't let the user actually say if they'll allow location services. The alert fires then disappears. Does this help anyone's diagnosis?
-(void)startLocation
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
Also, here's my didFinishLaunchingWithOptions method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UINavigationController *nav = [[UINavigationController alloc] init];
StartPageViewController *start = [[StartPageViewController alloc]init];
NSManagedObjectContext *context = [self managedObjectContext];
if (!context)
{
// Handle the error.
}
start.managedObjectContext = context;
nav.viewControllers = [NSArray arrayWithObjects:start, nil];
[_window addSubview:[nav view]];
[self.window makeKeyAndVisible];
return YES;
}
Try retaining your navigation controller by making it a strong property on your delegate.
At the moment, I don't see any code that would cause ARC not to release nav at the end of the method. That would release start, which would release context.
All I needed to change (so far) was:
self.window.rootViewController = nav;
instead of:
[_window addSubview:[nav view]];

Expected getter method not found, Xcode iOS

I am using Apple's newest Xcode for MacOS 10.7(Lion). I am trying to make a iPhone application. I'm new to the language and decided to load up apples guides. 'Your first iOS application'. It was good, taught me a few things but Its not working. I get Expected Getter Method Not Found On Object Of Type 'TestAppDelegate *'
How do i Fix this?
Heres the code:
TestAppDelegate.m
#import "TestAppDelegate.h"
#import "MyViewController.h"
#implementation TestAppDelegate
#synthesize window=_window;
#synthesize myViewController=_myViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MyViewController *aViewController = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
self.myViewController = aViewController;
// Or, instead of the line above:
// [self setMyViewController:aViewController];
[aViewController release];
self.window.rootViewController = self.MyViewController;
[self.window makeKeyAndVisible];
return YES;
}
/* Other methods omitted from the listing. */
- (void)dealloc {
[_myViewController release];
[_window release];
[super dealloc];
}
#end
The line:
self.window.rootViewController = self.MyViewController;
Has the problem
objective-c is case-sensitive. You wrote an upper-case M instead of lower-case.
self.window.rootViewController = self.myViewController;
Your window doesn't exist yet (at least from what I can see in your code). Add this before the line causing the SIGABRT:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];