ios 获得通讯录中联系人的所有属性 亲测,可行 兼容io6 和 ios 7
生活随笔
收集整理的這篇文章主要介紹了
ios 获得通讯录中联系人的所有属性 亲测,可行 兼容io6 和 ios 7
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
//獲取通訊錄中的所有屬性,并存儲在?textView?中,已檢驗,切實可行。兼容io6?和?ios?7?,而且ios7還沒有權限確認提示。 -()getAddressBook {ABAddressBookRef?addressBook?=?ABAddressBookCreate();CFArrayRef?results?=?ABAddressBookCopyArrayOfAllPeople(addressBook);????(?i?=?;?i?<?CFArrayGetCount(results);?i++){ABRecordRef?person?=?CFArrayGetValueAtIndex(results,?i);????????NSString?*personName?=?(NSString*)ABRecordCopyValue(person,?kABPersonFirstNameProperty);????????(personName?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,personName];????????NSString?*lastname?=?(NSString*)ABRecordCopyValue(person,?kABPersonLastNameProperty);????????(lastname?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,lastname];????????NSString?*middlename?=?(NSString*)ABRecordCopyValue(person,?kABPersonMiddleNameProperty);????????(middlename?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,middlename];????????NSString?*prefix?=?(NSString*)ABRecordCopyValue(person,?kABPersonPrefixProperty);????????(prefix?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,prefix];????????NSString?*suffix?=?(NSString*)ABRecordCopyValue(person,?kABPersonSuffixProperty);????????(suffix?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,suffix];????????NSString?*nickname?=?(NSString*)ABRecordCopyValue(person,?kABPersonNicknameProperty);????????(nickname?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,nickname];????????NSString?*firstnamePhonetic?=?(NSString*)ABRecordCopyValue(person,?kABPersonFirstNamePhoneticProperty);????????(firstnamePhonetic?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,firstnamePhonetic];????????NSString?*lastnamePhonetic?=?(NSString*)ABRecordCopyValue(person,?kABPersonLastNamePhoneticProperty);????????(lastnamePhonetic?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,lastnamePhonetic];????????NSString?*middlenamePhonetic?=?(NSString*)ABRecordCopyValue(person,?kABPersonMiddleNamePhoneticProperty);????????(middlenamePhonetic?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,middlenamePhonetic];????????NSString?*organization?=?(NSString*)ABRecordCopyValue(person,?kABPersonOrganizationProperty);????????(organization?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,organization];????????NSString?*jobtitle?=?(NSString*)ABRecordCopyValue(person,?kABPersonJobTitleProperty);????????(jobtitle?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,jobtitle];????????NSString?*department?=?(NSString*)ABRecordCopyValue(person,?kABPersonDepartmentProperty);????????(department?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,department];????????NSDate?*birthday?=?(NSDate*)ABRecordCopyValue(person,?kABPersonBirthdayProperty);????????(birthday?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,birthday];????????NSString?*note?=?(NSString*)ABRecordCopyValue(person,?kABPersonNoteProperty);????????(note?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,note];????????NSString?*firstknow?=?(NSString*)ABRecordCopyValue(person,?kABPersonCreationDateProperty);NSLog(,firstknow);????????NSString?*lastknow?=?(NSString*)ABRecordCopyValue(person,?kABPersonModificationDateProperty);NSLog(,lastknow);????????ABMultiValueRef?email?=?ABRecordCopyValue(person,?kABPersonEmailProperty);?????????emailcount?=?ABMultiValueGetCount(email);?????????(?x?=?;?x?<?emailcount;?x++){????????????NSString*?emailLabel?=?(NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(email,?x));????????????NSString*?emailContent?=?(NSString*)ABMultiValueCopyValueAtIndex(email,?x);textView.text?=?[textView.text?stringByAppendingFormat:,emailLabel,emailContent];}????????ABMultiValueRef?address?=?ABRecordCopyValue(person,?kABPersonAddressProperty);?????????count?=?ABMultiValueGetCount(address);????????(?j?=?;?j?<?count;?j++){????????????NSString*?addressLabel?=?(NSString*)ABMultiValueCopyLabelAtIndex(address,?j);textView.text?=?[textView.text?stringByAppendingFormat:,addressLabel];????????????NSDictionary*?personaddress?=(NSDictionary*)?ABMultiValueCopyValueAtIndex(address,?j);NSString*?country?=?[personaddress?valueForKey:(NSString?*)kABPersonAddressCountryKey];????????????(country?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,country];NSString*?city?=?[personaddress?valueForKey:(NSString?*)kABPersonAddressCityKey];????????????(city?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,city];NSString*?state?=?[personaddress?valueForKey:(NSString?*)kABPersonAddressStateKey];????????????(state?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,state];NSString*?street?=?[personaddress?valueForKey:(NSString?*)kABPersonAddressStreetKey];????????????(street?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,street];NSString*?zip?=?[personaddress?valueForKey:(NSString?*)kABPersonAddressZIPKey];????????????(zip?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,zip];NSString*?coutntrycode?=?[personaddress?valueForKey:(NSString?*)kABPersonAddressCountryCodeKey];????????????(coutntrycode?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,coutntrycode];}????????ABMultiValueRef?dates?=?ABRecordCopyValue(person,?kABPersonDateProperty);?????????datescount?=?ABMultiValueGetCount(dates);?????????(?y?=?;?y?<?datescount;?y++){????????????NSString*?datesLabel?=?(NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates,?y));????????????NSString*?datesContent?=?(NSString*)ABMultiValueCopyValueAtIndex(dates,?y);textView.text?=?[textView.text?stringByAppendingFormat:,datesLabel,datesContent];}????????CFNumberRef?recordType?=?ABRecordCopyValue(person,?kABPersonKindProperty);?????????(recordType?==?kABPersonKindOrganization)?{????????????NSLog();}??{????????????NSLog();}????????ABMultiValueRef?instantMessage?=?ABRecordCopyValue(person,?kABPersonInstantMessageProperty);?????????(?l?=?;?l?<?ABMultiValueGetCount(instantMessage);?l++){????????????NSString*?instantMessageLabel?=?(NSString*)ABMultiValueCopyLabelAtIndex(instantMessage,?l);textView.text?=?[textView.text?stringByAppendingFormat:,instantMessageLabel];????????????NSDictionary*?instantMessageContent?=(NSDictionary*)?ABMultiValueCopyValueAtIndex(instantMessage,?l);NSString*?username?=?[instantMessageContent?valueForKey:(NSString?*)kABPersonInstantMessageUsernameKey];????????????(username?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,username];NSString*?service?=?[instantMessageContent?valueForKey:(NSString?*)kABPersonInstantMessageServiceKey];????????????(service?!=?nil)textView.text?=?[textView.text?stringByAppendingFormat:,service];}????????ABMultiValueRef?phone?=?ABRecordCopyValue(person,?kABPersonPhoneProperty);?????????(?k?=?;?k<ABMultiValueGetCount(phone);?k++){????????????NSString?*?personPhoneLabel?=?(NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phone,?k));????????????NSString?*?personPhone?=?(NSString*)ABMultiValueCopyValueAtIndex(phone,?k);textView.text?=?[textView.text?stringByAppendingFormat:,personPhoneLabel,personPhone];}????????ABMultiValueRef?url?=?ABRecordCopyValue(person,?kABPersonURLProperty);?????????(?m?=?;?m?<?ABMultiValueGetCount(url);?m++){????????????NSString?*?urlLabel?=?(NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(url,?m));????????????NSString?*?urlContent?=?(NSString*)ABMultiValueCopyValueAtIndex(url,m);textView.text?=?[textView.text?stringByAppendingFormat:,urlLabel,urlContent];}????????NSData?*image?=?(NSData*)ABPersonCopyImageData(person);UIImageView?*myImage?=?[[UIImageView?alloc]?initWithFrame:CGRectMake(,?,?,?)];[myImage?setImage:[UIImage?imageWithData:image]];myImage.opaque?=?YES;[textView?addSubview:myImage];}CFRelease(results);CFRelease(addressBook); }
轉載于:https://my.oschina.net/u/2559341/blog/596852
總結
以上是生活随笔為你收集整理的ios 获得通讯录中联系人的所有属性 亲测,可行 兼容io6 和 ios 7的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: zabbix安装报错
- 下一篇: UVA 10917 Walk Throu