iphone - 应用程序在 iPhone 设备上意外终止,但在模拟器上运行良好

标签 iphone ios xcode

开发的应用程序在 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/

相关文章:

ios - 如何在 iOS 中创建 AppDelegate 共享实例?

ios - B2B 应用的 AppStore 问题

ios - NS编码: Save custom object and load to table view iOS

java - 在为 iOS 编译的 libGDX 项目中使用斯堪的纳维亚字母

iphone - 从另一个类调用函数 - Obj C

iphone - extAudioFile 数据...我得到正确的东西了吗?

IOS Contacts框架,如何将imageData编解码成String并通过infoDiscovery字典发送给MPC广告商

objective-c - 将textView的值赋值给int,IOS

ios - Swift 中类的函数调用中的 "Expression are not allowed at top level"

c++ - 如何从终端启动 C 应用程序,并将参数传递给 int main(int argc, char *argv[])?