2010-09-21 29 views
-1

我有一個應用程序使用用戶的地址簿來存儲聯繫人。我還希望以每個用戶爲基礎存儲其他信息(每個通訊錄條目基礎)。我允許用戶導入單個用戶,地址簿組或所有聯繫人。由於我希望繼續允許外部應用程序更改用戶地址簿,因此我不會導入所有信息。相反,我選擇爲每個導入的用戶更改地址簿條目,並添加一個kABPersonInstantMessageProperty密鑰。我想用[email protected]作爲用戶名填充到此密鑰。我想這將立即被最終用戶視爲a:不引人注目和b:鏈接到我的應用程序的信息(掛鉤外部聯繫人信息與我的應用程序添加和保持的內部信息)。唯一的問題?我不知道如何添加一個條目到kABPersonInstantMessageProperty密鑰。我已經想出瞭如何添加諸如「家庭地址」的多值條目,但是在搜索堆棧溢出時,我提出了有關此密鑰(kABPersonInstantMessageProperty)的問題中的4個(僅有四個!)條目。在用戶的地址簿中存儲記錄定位器kABPersonInstantMessageProperty字段

我的代碼的一部分用於將「家庭地址」添加到人員的地址簿條目下方,我承認我不知道如何將此更改爲kABPersonInstantMessageProperty。

ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType); 
NSMutableDictionary *addressDict = [[NSMutableDictionary alloc] init]; 

NSMutableString *street = [NSMutableString stringWithFormat:@"%i",i]; 
[street appendString:@" Main Street"]; 

[addressDict setObject:[NSString stringWithString:street] forKey:(NSString *)kABPersonAddressStreetKey];  
[addressDict setObject:@"San Jose" forKey:(NSString *)kABPersonAddressCityKey]; 
[addressDict setObject:@"CA" forKey:(NSString *)kABPersonAddressStateKey]; 

NSMutableString *zip = [NSMutableString stringWithString:@"95"]; 
[zip appendString:[NSString stringWithFormat:@"%00i",i]]; 

[addressDict setObject:zip forKey:(NSString *)kABPersonAddressZIPKey];  
ABMultiValueAddValueAndLabel(address, addressDict, kABHomeLabel, NULL); 
ABRecordSetValue(record, kABPersonAddressProperty, address, NULL); 

// add the record 
ABAddressBookAddRecord(addressBook, record, NULL); 

有人可以幫忙嗎?我會很感激。

+0

不要你恨它,當人們downvote問題不說爲什麼?在我的問題被自己問及(和回答)後,我幾乎登錄了一年...並且有人在3天前低估了這個問題! hrumph! Downvoters應在評論中列出,以便我們驗證我們爲什麼問它。這個問題有代碼和有問必答的正當理由。想知道任何人都可以用它來解決問題! – Jann 2011-07-25 06:16:23

回答

3

GOT IT!

這很簡單!感謝link text,他們遇到了同樣的問題,因爲缺乏谷歌解決方案。謝謝,凱西!

record是ABPerson記錄和所有的ABCreate東西已經完成,i是順序記錄定位整數...

 ABMutableMultiValueRef im = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType); 
     NSMutableDictionary *imDict = [[NSMutableDictionary alloc] init]; 
     [imDict setObject:@"MyAppName" forKey:(NSString*)kABPersonInstantMessageServiceKey]; 

     NSMutableString *iMID = [NSMutableString stringWithFormat:@"%i",i]; 
     [iMID appendString:@"[email protected]"]; 

     [imDict setObject:iMID forKey:(NSString*)kABPersonInstantMessageUsernameKey]; 
     ABMultiValueAddValueAndLabel(im, imDict, kABHomeLabel, NULL); 
     [imDict release]; 
     ABRecordSetValue(record, kABPersonInstantMessageProperty, im, NULL); 
+0

thx,一天中的英雄! – 2011-03-09 12:46:59

相關問題