我試圖實現一個聯繫人應用程序。NSOperationQueue ....無法識別的選擇器發送
在MyContactsViewController中,我試圖訪問聯繫人,如果授予訪問權限,我將從我的通訊錄中獲取聯繫人。 ContactHandler
是我的模型類(單例),它有一個名爲getAllContacts
的方法來獲取NSMutableArray中的聯繫人。
- (void)viewDidLoad {
[super viewDidLoad];
contactHandler = [ContactHandler sharedInstance];
if(!self.accessGranted){
NSOperationQueue *queue =[[ NSOperationQueue alloc]init];
[queue performSelectorOnMainThread:@selector(getAccessToAddressBook) withObject:self waitUntilDone:YES];
contactList = [contactHandler getAllContacts];
}
else{
contactList = [contactHandler getAllContacts];
}
}
-(BOOL)getAccessToAddressBook{
CNContactStore * contactStore = [[CNContactStore alloc] init];
if([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] == CNAuthorizationStatusNotDetermined){
[contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if(granted){
self.accessGranted = YES;
}
else{
self.accessGranted = NO;
}
}];
}
else if([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]== CNAuthorizationStatusAuthorized){
self.accessGranted = YES;
}
else{
self.accessGranted = NO;
}
return self.accessGranted;
}
但我得到這個錯誤 -
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSOperationQueue getAccessToAddressBook]: unrecognized selector sent to instance 0x137630700'
任何人都可以請幫助。
'[隊列performSelectorOnMainThread:@selector (getAccessToAddressBook)withObject:self waitUntilDone:YES];'你想要做什麼?這是導致問題的線路。 – Larme
通過按cmd +單擊,它是否轉到該方法?另請嘗試等待完成:否 – Hima
我正在嘗試獲取權限,然後才能獲取聯繫人。基本上我想在getAccessToAddressBook方法得到響應後調用getAllContacts方法。 – Natasha