ios - Address Book - Select email of Linked contact -
i trying fetch selected email property in delegate callback mentioned below
-(bool)peoplepickernavigationcontroller:(abpeoplepickernavigationcontroller *)peoplepicker shouldcontinueafterselectingperson:(abrecordref)person property:(abpropertyid)property identifier:(abmultivalueidentifier)identifier { if (property==kabpersonemailproperty) { abmultivalueref emails = abrecordcopyvalue(person, kabpersonemailproperty); if (abmultivaluegetcount(emails) > 0) { nsstring *email = (__bridge_transfer nsstring*) abmultivaluecopyvalueatindex(emails, abmultivaluegetindexforidentifier(emails,identifier)); [recipientemail settext:email]; [peoplepicker dismissviewcontrolleranimated:yes completion:nil]; } cfrelease(emails); } return no; }
but if select email property of linked contact (having single email) identifier 0, result first email-id of primary contact. eg: john - john@gmail.com john26@gmail.com roger (linked contact) - roger@gmail.com
when select roger@gmail.com john@gmail.com.
i have same issue. wrong email when select accounts multiple email addresses. when loop through selected abmutablemultivalueref...
for (cfindex ix = 0; ix < abmultivaluegetcount(emails); ix++) { cfstringref label = abmultivaluecopylabelatindex(emails, ix); cfstringref value = abmultivaluecopyvalueatindex(emails, ix); nslog(@"i have %@ address: %@", label, value); if (label) cfrelease(label); if (value) cfrelease(value); }
... multiple occurrences of same address, null labels.
> have (null) address: john@home.com > have _$!<work>!$_ address: jsmith@work.com > have _$!<home>!$_ address: john@home.com
the workaround try filter out null labels first, see if abmultivalueidentifier 'fits', , if not revert null labels. unless have found something?
edit: works me.
nsmutablearray *labeled = [nsmutablearray new]; abmutablemultivalueref emails = abrecordcopyvalue(person, kabpersonemailproperty); (cfindex ix = 0; ix < abmultivaluegetcount(emails); ix++) { cfstringref label = abmultivaluecopylabelatindex(emails, ix); cfstringref value = abmultivaluecopyvalueatindex(emails, ix); if (label != null) { [labeled addobject:(nsstring *)cfbridgingrelease(value)]; } if (label) cfrelease(label); if (value) cfrelease(value); } nsstring *email; if (labeled.count > identifier) { email = [labeled objectatindex:identifier]; } else { cfstringref emailref = abmultivaluecopyvalueatindex(emails, identifier); email = (nsstring *)cfbridgingrelease(emailref); }
Comments
Post a Comment