我在我的应用程序中使用地址簿。我正在后台线程中获取通讯录数据。如果我从后台打开我的应用程序,我的应用程序会崩溃并出现以下错误:
Application Specific Information:
[2786] was suspended with locked system files:
/private/var/mobile/Library/AddressBook/AddressBook.sqlitedb
在我的应用程序从后台启动后,当我的应用程序收到 UIApplicationDidBecomeActiveNotification 时,我正在后台线程中获取通讯录数据。这是我的代码
// In my ViewController.m
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appLaunchedFromBackground:)
name:UIApplicationDidBecomeActiveNotification object:nil];
// Some more code
}
-(void)appLaunchedFromBackground:(NSNotification *) notification {
NSLog(@"In appLaunchedFromBackground");
[self performSelectorInBackground:@selector(getUpdatedAddressBookData) withObject:nil];
}
-(void)getUpdatedAddressBookData {
NSLog(@"In %s",__PRETTY_FUNCTION__);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
AddressBook *addBook = [[AddressBook alloc]init];
[addBook fetchAddressBookDataInBackground];
[addBook release];
[pool drain];
}
我的应用程序中也有 CALL 功能。如果我打电话给我的应用程序并在通话结束后我再次启动我的应用程序两次我的应用程序崩溃。对于 CALL,我使用了以下代码:
+(void)makeCallToSelectedContact:(NSString*)phoneNo{
NSMutableString *phoneNumber = [NSMutableString stringWithString:phoneNo];
[phoneNumber replaceOccurrencesOfString:@" "
withString:@""
options:NSLiteralSearch
range:NSMakeRange(0, [phoneNumber length])];
[phoneNumber replaceOccurrencesOfString:@"("
withString:@""
options:NSLiteralSearch
range:NSMakeRange(0, [phoneNumber length])];
[phoneNumber replaceOccurrencesOfString:@")"
withString:@""
options:NSLiteralSearch
range:NSMakeRange(0, [phoneNumber length])];
NSLog(@"phoneNumber => %@",phoneNumber);
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNumber]]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNumber]]];
}
else {
NSLog(@"Unable to open");
[self showAlertWithTitle:@"Alert" andMessage:@"This Device Doesn't Support Call Functionality"];
}
}
如何解决崩溃问题?任何形式的帮助都将受到高度赞赏。谢谢。