xcode 应用程序仅在 iPhone 设备上崩溃,而不在模拟器中崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8427516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
App crash only on iPhone Device and not in Simulator
提问by Najeebullah Shah
In my app, when I press a button the method called for that button first assigns my textfield texts directly to NSArray
object like:
在我的应用程序中,当我按下一个按钮时,该按钮调用的方法首先将我的文本字段文本直接分配给NSArray
对象,例如:
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"
当我在模拟器上运行我的应用程序时,没有发生应用程序崩溃,但是当我在我的 iPhone 设备上运行它时,它给出: Thread 1: program recieved signal "EXC_BAC_ACCESS"
Can anybody tell why this happens and what's the solution for this scenario?
谁能告诉为什么会发生这种情况以及这种情况的解决方案是什么?
采纳答案by djromero
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?
使用数组创建涉及的所有对象都initWithObjects
应该是实际对象。有没有足够的代码在你的问题知道lat
和longt
有对象了。他们是吗?
If they aren't, wrap them with [NSNumber numberWithFloa:<# the float #>
].
如果不是,请用[NSNumber numberWithFloa:<# the float #>
]包裹它们。
If that's not the problem, check SO questions regarding EXC_BAC_ACCESS
to learn to debug them.
如果这不是问题,请检查有关EXC_BAC_ACCESS
学习调试它们的SO 问题。
回答by Niko
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.
在 XCode 中,转到菜单“编辑方案”,选择运行配置并添加“NSZombieEnabled”,如下图所示,当您的应用程序崩溃时,它将为您提供有关崩溃的其他信息,以帮助您调试它。
EDIT
编辑
Note that when your application debug is over, remove the NSZombieEnabled command as it impacts the application performances
请注意,当您的应用程序调试结束时,请删除 NSZombieEnabled 命令,因为它会影响应用程序性能
回答by utsabiem
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.
从模拟器中删除应用程序/从 Mac 中删除构建文件/从 XCode 中清除产品,然后再次在模拟器中运行它。检查它现在是否在模拟器中崩溃。
看看这个链接: EXC_BAD_ACCESS signal received收到 EXC_BAD_ACCESS 信号。另外,在将它们放入数组之前,先获取所有 textfield.texts 的 NSLog。可能是其中之一变成了零。回答by nikita21
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.
模拟器具有整个机器的内存空间......但iphone为单个应用程序定义了沙箱的内存。
回答by onuryilmaz
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];
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.
如果在您开始解决这些内存管理问题后,您的应用程序开始减少崩溃,则表明您走在正确的道路上。所以继续释放。