iphone - Unable to fetch mobile numbers from Contact List. iOS6 -
i new iphone app development(using ios6) , have been facing problem fetching mobile numbers contact list uitableviewcontroller. can first name , last name correctly phone numbers being returned null. not understand reason behind this.what doing wrong? code follows:
nsmutablearray *people = (__bridge_transfer nsmutablearray *) abaddressbookcopyarrayofallpeople (addressbookref); nsstring *firstname = (__bridge_transfer nsstring *)abrecordcopyvalue((__bridge abrecordref)([people objectatindex:indexpath.row]), kabpersonfirstnameproperty); nsstring *lastname = (__bridge_transfer nsstring *)abrecordcopyvalue((__bridge abrecordref)([people objectatindex:indexpath.row]), kabpersonlastnameproperty); abmultivalueref phonenumbers = abrecordcopyvalue((__bridge abrecordref)([people objectatindex:indexpath.row]),kabpersonphoneproperty); if (([firstname isequaltostring:@""] || [firstname isequaltostring:@"(null)"] || firstname == nil) && ([lastname isequaltostring:@""] || [lastname isequaltostring:@"(null)"] || lastname == nil)) { // nothing } else { aname = [nsstring stringwithformat:@"%@ %@", firstname, lastname]; if ([firstname isequaltostring:@""] || [firstname isequaltostring:@"(null)"] || firstname == nil) { aname = [nsstring stringwithformat:@"%@", lastname]; } if ([lastname isequaltostring:@""] || [lastname isequaltostring:@"(null)"] || lastname == nil) { aname = [nsstring stringwithformat:@"%@", firstname]; } //[self.tableitems addobject:aname]; nslog(@"%@ added",aname); } //fetch multiple phone nos. , use 0th id person = people[indexpath.row]; abmultivalueref multi = abrecordcopyvalue((__bridge abrecordref)(person), kabpersonphoneproperty); nsstring* phone = (__bridge nsstring*)abmultivaluecopyvalueatindex(multi, 0); nslog(@"%@",phone); [cell.detailtextlabel settext:phone]; [cell.textlabel settext:aname]; return cell;
here full working code
-(void)getaddressbook { contacts = [[nsmutablearray alloc]init]; if (abaddressbookcreatewithoptions) { @try { abaddressbookref addressbook = abaddressbookcreate(); // nsarray *people = (nsarray*)abaddressbookcopyarrayofallpeople(addressbook); if (!addressbook) { nslog(@"opening address book"); } cfarrayref allpeople = abaddressbookcopyarrayofallpeople(addressbook); cfindex npeople = abaddressbookgetpersoncount(addressbook); nslog(@"opening address book ==%ld",npeople); (int i=0;i < npeople;i++) { nsmutabledictionary *dofperson=[nsmutabledictionary dictionary]; abrecordref ref = cfarraygetvalueatindex(allpeople,i); nsstring *contact; abmultivalueref phones =(__bridge abmultivalueref)((__bridge nsstring*)abrecordcopyvalue(ref, kabpersonphoneproperty)); cfstringref firstname, lastname; nsmutablearray *array = [[nsmutablearray alloc]init]; nsstring *email; firstname = abrecordcopyvalue(ref, kabpersonfirstnameproperty); lastname = abrecordcopyvalue(ref, kabpersonlastnameproperty); abmultivalueref multivalueref = abrecordcopyvalue(ref, kabpersonemailproperty); array = [(__bridge nsmutablearray *)abmultivaluecopyarrayofallvalues(multivalueref) mutablecopy]; email = ([array count] > 0) ? array[0] : @""; if(firstname) { contact = [nsstring stringwithformat:@"%@", firstname]; if(lastname) contact = [nsstring stringwithformat:@"%@ %@",firstname,lastname]; } [dofperson setobject:contact forkey:@"name"]; [dofperson setobject:[nsstring stringwithformat:@"%d", i] forkey:@"id"]; [dofperson setobject:[nsstring stringwithformat:@"%@",@""] forkey:@"found"]; [dofperson setobject:email forkey:@"email"]; nsstring* mobilelabel; for(cfindex j = 0; j< abmultivaluegetcount(phones); j++) { mobilelabel = (__bridge nsstring*)abmultivaluecopylabelatindex(phones, j); if([mobilelabel isequaltostring:(nsstring *)kabpersonphonemobilelabel]) { [dofperson setobject:(__bridge nsstring*)abmultivaluecopyvalueatindex(phones, j) forkey:@"phone"]; } else if ([mobilelabel isequaltostring:(nsstring*)kabpersonphoneiphonelabel]) { [dofperson setobject:(__bridge nsstring*)abmultivaluecopyvalueatindex(phones, j) forkey:@"phone"]; break ; } } [contacts addobject:dofperson]; } } @catch (nsexception * e) { nslog(@"exception: %@", e); } dispatch_async(dispatch_get_main_queue(), ^{ }); } the phone numbers taken abmultivalueref phones =(__bridge abmultivalueref)((__bridge nsstring*)abrecordcopyvalue(ref, kabpersonphoneproperty));
Comments
Post a Comment