开发的应用程序在 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
基本上,问题发生在我触发 NSTimer(倒计时)并达到“1”时。卡住一段时间,然后终止。
这是定时器初始化的方法:
- (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);
}
有没有人知道这个。真的……迷路了!
提前致谢
最佳答案
我不确定这是否是崩溃的根源,但您确实在这里遇到了问题:
[self performSelector:@selector(attackTo:attacker:) withObject:nil afterDelay:20.0];
基本上,选择器调用有两个 :
的事实意味着它需要两个参数。如果您使用 performSelector:withObject:afterDelay:
方法,则只能将其与具有一个参数的方法一起使用。
例如,
[self performSelector:@selector(doSomething:) withObject:object afterDelay:20.0f]
相当于
[self doSomething:object]
大约20秒后执行。
在这种情况下,你有一个不匹配,因为你的 @selector
有 两个 参数,所以你不能将它与那个特定的 performSelector
一起使用方法。
虽然有一个 performSelector:withObject:withObject
方法接受两个参数,但它没有 delay
参数。您可能需要改用 NSInvocation
,或者更改 attackTo:attacker:
以便它使用单个参数(例如,NSDictionary)。
关于iphone - 应用程序在 iPhone 设备上意外终止,但在模拟器上运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13504537/