xcode 应用程序在 iPhone 设备上意外终止,但在模拟器上运行良好
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13504537/
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 terminated unexpectedly on iPhone device, but working fine on Simulator
提问by toto7
The application that developing is running fine on Xcode simulator, but when I am testing it on real device is terminated. Below is what my phone's console prints out when app is terminated.
开发的应用程序在 Xcode 模拟器上运行良好,但是当我在真实设备上测试它时被终止。以下是我的手机控制台在应用程序终止时打印出来的内容。
Nov 22 00:51:09 iPhone ReportCrash[3862] <Notice>: Formulating crash report for process CoL[3860]
??Nov 22 00:51:09 iPhone ReportCrash[3862] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
??Nov 22 00:51:09 iPhone com.apple.launchd[1] (UIKitApplication:pan.ConquestOfLancaster[0xd857][3860]) <Warning>: (UIKitApplication:pan.ConquestOfLancaster[0xd857]) Job appears to have crashed: Segmentation fault: 11
??Nov 22 00:51:09 iPhone backboardd[52] <Warning>: Application 'UIKitApplication:pan.ConquestOfLancaster[0xd857]' exited abnormally with signal 11: Segmentation fault: 11
??Nov 22 00:51:09 iPhone ReportCrash[3862] <Notice>: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/CoL_2012-11-22-005109_iPhone.plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0
??Nov 22 00:51:09 iPhone awdd[3863] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Basically, the problem occurs when I am firing a NSTimer (countdown) and reach '1'. Freeze for a while and then terminated.
基本上,当我触发 NSTimer(倒计时)并达到“1”时就会出现问题。冻结一段时间然后终止。
Here is the method where timer initialised:
这是定时器初始化的方法:
- (void)MapMenu:(MapMenu *)menu didSelectButton:(NSInteger)index{
if (index == 0) {
if (self.owner == nil && distance < 10) {
CountDownTimer* countDown = [[CountDownTimer alloc]init];
[countDown startTimerOn:parentView];
[self performSelector:@selector(attackTo:attacker:) withObject:nil afterDelay:20.0];
}
else if (self.owner == @"Player_1")
NSLog(@"You have already occupy this building with name, %@", self.title);
}
}
- (void) attackTo: (BuildingViewController*) selectedBuilding attacker: (NSString*) attacker{
self.owner = @"Player_1";
NSLog(@"Building has a new owner with name, %@", self.owner);
}
Does anyone has a clue for this. Really ... lost!
有没有人有这方面的线索。真的……输了!
Thanks in advance
提前致谢
回答by Matthew Gillingham
I am not sure if this is the source of the crash, but you do have a problem right here:
我不确定这是否是崩溃的根源,但您确实在这里遇到了问题:
[self performSelector:@selector(attackTo:attacker:) withObject:nil afterDelay:20.0];
Basically, the fact that selector call has two :means that it is expecting two arguments. If you use the method performSelector:withObject:afterDelay:, you can only use it with a method that has one argument.
基本上,选择器调用有两个事实:意味着它需要两个参数。如果使用 method performSelector:withObject:afterDelay:,则只能将其与具有一个参数的方法一起使用。
For example,
例如,
[self performSelector:@selector(doSomething:) withObject:object afterDelay:20.0f]
is equivalent to
相当于
[self doSomething:object]
and it will be performed after about 20 seconds.
它会在大约 20 秒后执行。
In this case, you have a mismatch because your @selectortakes twoarguments, so you can not use it with that particular performSelectormethod.
在这种情况下,您有一个不匹配,因为您@selector需要两个参数,因此您不能将它与该特定performSelector方法一起使用。
While there is a performSelector:withObject:withObjectmethod that takes two arguments, it does not have a delayargument. You might need to use NSInvocationinstead, or change the attackTo:attacker:so that it uses a single argument (for example, an NSDictionary).
虽然有一个performSelector:withObject:withObject接受两个参数的方法,但它没有delay参数。您可能需要NSInvocation改用或更改 以attackTo:attacker:使其使用单个参数(例如,NSDictionary)。
回答by atreat
I see your using a class called CountDownTimer. Is this a subclass of NSTimer? If so, you should read the subclassing notes in the NSTimer class reference. NSTimer Class Reference
我看到您使用了一个名为 CountDownTimer 的类。这是 NSTimer 的子类吗?如果是这样,您应该阅读 NSTimer 类参考中的子类化说明。 NSTimer 类参考
Basically, it says don't do it. Actually no not even basically, it says don't do it.
基本上,它说不要这样做。实际上没有甚至根本没有,它说不要这样做。
While your reading the class reference take a look at how to implement a callback after n seconds. Personally, I like + scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:
在阅读类参考时,请查看如何在 n 秒后实现回调。就个人而言,我喜欢+ scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:

