我有一個應用程序掃描網站上的文本,以獲取信息並將其放入我的應用程序。所以在這種情況下,我正在檢索用戶在Facebook上發佈的通知數量。一切正常,除了應用程序隨機崩潰。這是我搜索文本中的數字的代碼:iPhone SDK:NSScanner隨機崩潰
NSScanner *theScanner = [NSScanner scannerWithString:facebookTextF];
NSScanner *theScanner2 = [NSScanner scannerWithString:facebookTextFa];
[theScanner scanUpToString:@"Notifications" intoString:&facebookTextFa] ;
[theScanner scanUpToString:@"\n" intoString:&facebookTextF] ;
NSString *NotificationsValue;
if ([facebookTextF isEqualToString:@"Notifications"]) {
NotificationsValue = @"0";
NSLog(@"%@", NotificationsValue);
} else {
[theScanner2 scanUpToString:@"Notifications" intoString:nil] ;
[theScanner2 setScanLocation:([theScanner2 scanLocation] + 13)];
[theScanner2 scanUpToString:@"\n" intoString:&facebookTextFa] ;
NSLog(@"%@", facebookTextFa);
}
此代碼運行良好,但隨機崩潰。這裏是崩潰日誌我得到:
iphone[654:907] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSConcreteScanner setScanLocation:]: Range or index out of bounds'
*第一擲調用堆棧: (0x3361b6c3 0x398b397f 0x3361b5e5 0x34d2632f 0x25147 0x34dbf78b 0x335f09ff 0x335f06b1 0x335ef321 0x3356239d 0x33562229 0x39fad31b 0x3402b8f9 0x22267 0x22208) 的libC++ abi.dylib:終止叫拋出異常
這個崩潰隨機發生,不管是什麼。例如,如果我離開它運行一段時間,7分鐘後只是隨機崩潰。不知道什麼是錯的。 謝謝你的期待。如果您需要更多信息,請告訴我。