How can I diagnose this error?
Application Specific Information:
MyApp failed to launch in time
Elapsed total CPU time (seconds): 4913.443 (user 3868.270, system 1045.173), 56% CPU
Elapsed application CPU time (seconds): 0.010, 0% CPU
Backtrace not available
Unknown thread crashed with unknown flavor: 5, state_count: 1
Binary Images:
0x2fe00000 - 0x2fe26fff dyld armv7 <a11905c8ef7906bf4b8910fc551f9dbb> /usr/lib/dyld
Here is my didFinishLaunching method:
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if(getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled"))
{
NSLog(#"NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");
}
// Override point for customization after application launch.
[[NSNotificationCenter defaultCenter] addObserver: self selector: #selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
//Check for connectivity
internetReach = [[Reachability reachabilityForInternetConnection] retain];
[internetReach startNotifer];
[self updateInterfaceWithReachability: internetReach];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}
You're probably doing a lot of setup work in your AppDelegate's application:didFinishLaunching method.
You should make sure this function exits as soon as possible. Any setup-work that takes time (network access for example) should be done asynchronously in your application. While this is going on, you can show a spinner to indicate to the user that the application is loading.
In order to add so information to Philippe Leybaert response.
If the application take to much time to start the main thread will be kill so the application will crash.
When you're using the simulator, it will not crash.
When you are using your iphone connected to xcode it will not crash.
When you send it for App Store it might be accepted if the Apple tester is using a fast iPhone
When your users on slow like iPhone 3S will crash
A way to test this issu before submitting is to deploy to testflight or with adhoc and install it on the slower device you want to support.
Just try to divide your application:didFinishLaunchingWithOptions: method code to different function calls and make those calls in background using the threads other then main and make sure that application:didFinishLaunchingWithOptions: method returns as soon as possible
you can use
dispatch_async(dispatch_get_main_queue(), ^{
//put your code
}
I have resolved the issue using this code !
Related
I am using a Burst mode In my App Using UIImagePickerController, Once when I complete my App with More Number of Images taken The App is getting Crashed Showing Error:
App quit Unexpectedly Terminated due to Memory Pressure
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[arrayImages addObject:image];
if (picTaken) {
[imagePicker takePicture];
}
else
{
[imagePicker dismissViewControllerAnimated:YES completion:^{
[self imagePlace];//Where i get All Images in a View presented same as in IOS camera Video//
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureSessionDidStartRunningNotification object:nil];
}];
}
}
This is All related to memory as if your iOS App runs and When a low memory condition is detected on an iOS device, the virtual memory system sends out notifications asking applications to release memory. These notifications are sent to all running applications and processes, in an effort to reduce the total amount of memory in use.
If memory usage remains high, the system may terminate background processes to ease memory pressure. If enough memory can be freed, your application will continue to run and no crash report will be generated. Otherwise, your app will be terminated by iOS, and a low memory report will be generated. For More you can review this.
So you can use Instruments tool for resolving this problem and detect the memory usage and leakage and follow the memory management technique.
Whenever there is a connection problem, a slow connection on 2G , etc., my app crashes with the following log:
What I can get from the log is, that it crashes on sendSynchronousRequest method of the NSURLConnection. How do I know what exactly is the problem, and how do I solve it?
I have put Reachability methods, given by Apple, but the return YES to both Internet reachability and Host reachability. It's just that the internet connection is very slow.
On Fast connections (Wifi), it works perfectly well.
Edit:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window setFrame:[[UIScreen mainScreen] bounds]];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//singleton
u=[[U5 alloc]init];
m_tUSyncPersistableConfig = [[USyncPersistableConfig alloc] init] ;
m_commonObj = [[CommonClass alloc] init] ;
u.m_tUSyncPersistableConfig=m_tUSyncPersistableConfig;
u.commonObj = m_commonObj;
//register for push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
//load persisting data : from sqlite database
[u loadPreferences:m_tUSyncPersistableConfig];
window.rootViewController = tabBarController;
[window makeKeyAndVisible];
if (![[NSUserDefaults standardUserDefaults] boolForKey:#"HasLaunchedOnce"]) {
//first launch//setting some values
}else {
//not first launch
}
if (![[NSUserDefaults standardUserDefaults] boolForKey:#"HasLaunchedOnce"] || [u.m_tUSyncPersistableConfig.mUserName isEqualToString:#""] || !u.m_tUSyncPersistableConfig.mUserName)
{
// This is the first launch ever
//present login page
}
else
{
// app already launched
[[u commonObj] performSelectorInBackground:#selector(getAccountInfo) withObject:nil];
}
return YES;
}
I would strongly recommend moving away from synchronous NSURLConnection web requests. It's not recommended by Apple and is considered bad design. I suggest moving to asynchronous requests -- it might sidestep your problem, and you can handle errors with the NSURLConnection delegate method.
Running synchronous requests in background threads is fine in general.
But the crash report shows that the synchronous request is running on the main thread. So there is at least one location where you are not running it in the background thread. And on the main thread it will block the UI and the iOS watchdog process will notice this and kill the app on startup.
So make sure, that you are never ever using synchronous requests on the main thread!
You are saying that you are doing this, but maybe you are doing it wrong. Show the code that is actually calling the connection methods. If you symbolicate the crash report it will also show these locations in the frames 8 to 10 of the thread 0 stack trace.
When i keep my application open for awhile, the iPhone/iPod locks the screen. When i unlock it my application gets stuck for like 2 seconds and then it resumes and keep functioning as usual. Why is this ? and how can i prevent it ?
To prevent this from hapenning is there any PLIST method where we could stop the process of the application when it goes to a locked screen (Might not be a better idea)
In your application delegate do you have any code that could slow down your app? Check the following methods?
-(void) applicationWillResignActive:(UIApplication *)application
-(void) applicationDidBecomeActive:(UIApplication *)application
-(void) applicationDidEnterBackground:(UIApplication*)application
-(void) applicationWillEnterForeground:(UIApplication*)application
-(void) applicationWillTerminate:(UIApplication *)application
Also use the above methods ensure you application suspends properly.
Log when your app receives a memory warning inside:
-(void) applicationDidReceiveMemoryWarning:(UIApplication *)application
Maybe when you suspend or reopen your app some there is a memory issue.
I'm not quite sure about the answer for your first question (you maybe do some heavy things inside the applicationDidBecomeActive method or the app simply reallocates memory), but i can answer the second one.
You can simply prevent the auto lock by calling:
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
A good palce for this is inside the applicationDidFinishLaunching method of the app delegate.
Hi I am just starting to develop Iphone apps, it's my first day. And I have to use some code a colleague gave me (he has xcode 4.1 or 4.2) l just to quickly try it out but It doesn't compile and I don't understand why. I have iphone SDK 3.1 and xcode 3.2 (i think). Updating to any other version is out of the question so is there a way I could fix these compilation errors?
I get the following errors in iLikeItAppDelegate.m
#synthesize window=_window;
!synthesized property 'window' must either be named the same as a compatible iva or must
explicitly name an ivar
#synthesize viewController=_viewController;
!kind of similar comment here
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
When I opened the project i tried to compile and it said something about iphoneos not found and the I had it changed to one of the sdks I have and now i get these weird errors. Please anybody help me thanks
EDIT: I managed to replace some staff by other and now I have this class:
#import "iLikeItAppDelegate.h"
#import "iLikeItViewController.h"
#implementation iLikeItAppDelegate
#synthesize window;
#synthesize viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//self.window.viewController
//self.window.rootViewController = self.viewController;
[window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
*/
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}
- (void)applicationWillTerminate:(UIApplication *)application
{
/*
Called when the application is about to terminate.
Save data if appropriate.
See also applicationDidEnterBackground:.
*/
}
- (void)dealloc
{
[window release];
[viewController release];
[super dealloc];
}
#end
but I have another compilation errors now and ones I don't even understand:
"__Block_object_dispose", referenced from:
___destroy_helper_block_1 in iLikeItViewController.o
___destroy_helper_block_3 in iLikeItViewController.o
___destroy_helper_block_4 in iLikeItViewController.o
___destroy_helper_block_2 in iLikeItViewController.o
"__Block_object_assign", referenced from:
___copy_helper_block_1 in iLikeItViewController.o
___copy_helper_block_3 in iLikeItViewController.o
___copy_helper_block_4 in iLikeItViewController.o
___copy_helper_block_2 in iLikeItViewController.o
"__NSConcreteStackBlock", referenced from:
__NSConcreteStackBlock$non_lazy_ptr in iLikeItViewController.o
(maybe you meant: __NSConcreteStackBlock$non_lazy_ptr)
ld: symbol(s) not found
collect2: ld returned 1 exit status
Could anybody help plz I need to learn these basics steps to transform xcode 4 projetcs into 3 because I have snow Leopard and that's the latest version the system lets me install.
rootViewController property is available in iOS 4.0 and later , read here
My advice : get newest SDK
I want to check for a valid network connection. I followed Apple's Reachability example and put my check in applicationDidFinishLaunching
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if(getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled"))
{
NSLog(#"NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");
}
// Override point for customization after application launch.
[[NSNotificationCenter defaultCenter] addObserver: self selector: #selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
//Check for connectivity
internetReach = [[Reachability reachabilityForInternetConnection] retain];
[internetReach startNotifer];
[self updateInterfaceWithReachability: internetReach];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}
However, my app will crash sometimes with the error Application Failed to Launch in Time
I have posted my crash as an SO question here: Application Failed to Launch in Time
I'm not sure where I should perform the reachability check?
A Reachability check could take a significant amount of time (30 seconds or more) depending on network conditions. But if your app's UI does not respond for some number of seconds (much less than 30), the OS assumes that it is dead and kills it.
If you do your Reachability check in a background thread, not the UI thread, then your UI will stay responsive, and neither the OS nor the user will assume that your app has locked up or crashed.
In -applicationDidBecomeActive you may call a method in the background that uses the reachability code with -performSelectorInBackground:withObject:.