所以我有一個應用程序使用NSTimer。問題是,當NSTimer
運行時,我的應用程序將崩潰EXC_BAD_ACCESS
。我只是開始使用objective-c,所以我不知道如何正確調試它。如果我認爲請撥打-(void)logIn{}
與[self logIn];
,該應用程序將起作用。 我的代碼:
.HNSTimer崩潰我的應用程序
@interface DJ_WAppDelegate : NSObject {
NSTimer *loginTimer;
}
-(void)logIn;
@end
.M
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[self logIn]; // this works
loginTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(logIn) userInfo:nil repeats:YES]; // this fails
}
- (void)logIn {
NSLog(@"Logging in...");
// if I comment out these 2 lines it works with the NSTimer!?... (I've would have more code below)
NSURL *loginConn = [NSURL URLWithString:[NSString stringWithFormat:@"some-website.com"]];
NSInteger loginReturn = [[NSString stringWithContentsOfURL:loginConn encoding:NSASCIIStringEncoding error:nil] intValue];
// when "loginReturn" return "OK" the timer (loginTimer) will be stopped with: [loginTimer invalidate];
// more code would be below... (which works!)
}
所以這個問題是與NSURL它認爲。 感謝您的幫助。
編輯1: 這裏的崩潰堆棧:
EException Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000020
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Application Specific Information:
objc_msgSend() selector name: respondsToSelector:
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x9603bed7 objc_msgSend + 23
1 com.apple.CoreFoundation 0x922ed5f2 _CFStringAppendFormatAndArgumentsAux + 3138
2 com.apple.CoreFoundation 0x922ec979 _CFStringCreateWithFormatAndArgumentsAux + 105
3 com.apple.Foundation 0x9656ebfb -[NSPlaceholderString initWithFormat:locale:arguments:] + 163
4 com.apple.Foundation 0x9656eaae +[NSString stringWithFormat:] + 88
5 com.who.DJ-W 0x00001d56 -[DJ_WAppDelegate logIn] + 116 (DJ_WAppDelegate.m:108)
6 com.apple.Foundation 0x965b08d4 __NSFireTimer + 141
7 com.apple.CoreFoundation 0x922ffadb __CFRunLoopRun + 8059
8 com.apple.CoreFoundation 0x922fd464 CFRunLoopRunSpecific + 452
9 com.apple.CoreFoundation 0x922fd291 CFRunLoopRunInMode + 97
10 com.apple.HIToolbox 0x91646e04 RunCurrentEventLoopInMode + 392
11 com.apple.HIToolbox 0x91646bb9 ReceiveNextEventCommon + 354
12 com.apple.HIToolbox 0x91646a3e BlockUntilNextEventMatchingListInMode + 81
13 com.apple.AppKit 0x9265378d _DPSNextEvent + 847
14 com.apple.AppKit 0x92652fce -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 156
15 com.apple.AppKit 0x92615247 -[NSApplication run] + 821
16 com.apple.AppKit 0x9260d2d9 NSApplicationMain + 574
17 com.who.DJ-W 0x00001c92 start + 54
希望這有助於...查找錯誤
編輯2:
隨着殭屍模式上,我得到這個:*** -[CFString respondsToSelector:]: message sent to deallocated instance 0x46d550
我希望這有助於。
編輯3:
要Ball:這裏是原來的URL(帶走這裏的域)/DJW/work.php?user=iBlackbirdi&udid=00000000-0000-1000-80005&key=660e5744e&cmd=slocau&type=get
如果您發佈崩潰堆棧,找出崩潰的情況會更容易。 – smorgan
定時器何時應該停止射擊?請爲您的活動可執行文件[請啓用NSZombie](http://cocoa-nut.de/?p=16)並查看控制檯輸出是否產生新的內容。 –
我不知道如果你的原始字符串的URL包括一些網址編碼%escapes這會混淆stringWithFormat – kball