[英]How to Fetch username only from the result set
選擇聯系人的Twitter詳細信息時,如何僅從通訊簿獲取用戶名值
if ( property == kABPersonSocialProfileProperty) {
ABMultiValueRef multi = ABRecordCopyValue(person, property);
for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++) {
CFStringRef socialLabel = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(multi, identifier));
CFStringRef social = ABMultiValueCopyValueAtIndex(multi, i);
NSDictionary* personaddress =(NSDictionary*) ABMultiValueCopyValueAtIndex(multi, i);
NSString*twitterdetails = [personaddress valueForKey:(NSString *)kABPersonSocialProfileServiceTwitter];
NSLog(@"%@ twitterdetails",twitterdetails);
NSString *aString = (NSString *)social;
NSLog(@"%@ aString",aString);
}
我得到如下結果
{
service = twitter;
url = "http://twitter.com/manoas2136";
username = manoas2136;
} aString
請告訴我如何從上述結果集中獲取用戶名
試試這個代碼
NSDictionary* personalDetails = [NSDictionary dictionaryWithDictionary:(NSDictionary*)ABMultiValueCopyValueAtIndex(multi, i)];
NSString* aString = [personalDetails valueForKey:@"username"];
NSLog(@"%@ aString",aString);
結果manoas2136 aString
您將NSDictionary值轉換為字符串,以便將NSDictionary的所有結果匯總為NSString,因此您可以使用valueForKey僅提取用戶名:
我已經嘗試過這種方式來從iPhone聯系人列表中獲取Twitter地址。 而且效果很好..
ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonSocialProfileProperty);
for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++)
{
NSDictionary* personalDetails = [NSDictionary dictionaryWithDictionary:(NSDictionary*)ABMultiValueCopyValueAtIndex(multi, i)];
NSLog(@"%@",personalDetails);
NSString* aString1 = [personalDetails valueForKey:@"username"];
NSLog(@"%@ aString",aString1);
Twitter.text = [personalDetails valueForKey:@"username"];
}
//get Twitter Address end....
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.