简体   繁体   中英

App crash only on iPhone Device and not in Simulator

In my app, when I press a button the method called for that button first assigns my textfield texts directly to NSArray object like:

 val = [[NSArray alloc] initWithObjects: nameText.text, cellText.text, p_emText.text, 
                                      p_cnfrmText.text, s_emText.text, s_cnfrmText.text,
                                      emailText.text, ecnfrmText.text, lat, longt,  
                                      nil];

when I run my app on simulator no app crashing occurs, but when I run it on my iPhone device it gives: Thread 1: program recieved signal "EXC_BAC_ACCESS"

Can anybody tell why this happens and what's the solution for this scenario?

In XCode, go to menu "edit scheme", choose the running configuration and add 'NSZombieEnabled' like in the picture below, when your apps crashes, it will provide you additional infos on the crash that should help you debug it.

在此输入图像描述

EDIT

Note that when your application debug is over, remove the NSZombieEnabled command as it impacts the application performances

All objects involved in array creation using initWithObjects should be actual objects. There is no enough code in your question to know if lat and longt are objects too. Are they?

If they aren't, wrap them with [NSNumber numberWithFloa:<# the float #> ].

If that's not the problem, check SO questions regarding EXC_BAC_ACCESS to learn to debug them.

Most probably your app is crashing due to memory issues since it is not crashing in simulator, try to release all objects that you allocate at the points you are done with them.

If you have your custom objects which you allocate and initialize as;

MyCustomClass *myObject = [[MyCustomClass alloc] init];

you need to release them as

[myObject release];

especially if they have members which are assigned big sized images or other kind of data.

If your app starts to crash less after you start solving these memory management issues, it shows that you are on the right way. So keep releasing.

Delete the app from simulator/ delete the build file from Mac/ clean the product from XCode and then again run it in simulator. Check if it crashes in simulator now.

Take a look at this link : EXC_BAD_ACCESS signal received . Also, Take NSLog of all the textfield.texts before putting them in array. May be one of them has become nil.

it may be a case of memory managemnet...have you released all the objects after their use?

simulator has the memory space of whole of the machine...but iphone has a defined memory of a sandbox for a single app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM