1

これは非常に特殊なケースです。誰かがすでにどこかでこれを解決したと思いますが、私がそれを見つけるのは簡単ではありません。

状況:

1)オブジェクトはNSString、address1、address2、phoneという名前のオブジェクトを返します。

[anObject name];
[anObject address1];
[anObject address2];
[anObject name];

2)これらのオブジェクトを使用して、最初に入力した値を準備ABUnknownPersonViewControllerしたいので、ユーザーはそれらをアドレス帳に保存する前に入力する必要はありません。

私はiOSドキュメントを見て、GoogleとStackOverflowを検索しましたが、この単純な状況に対する正しい答えを見つけることができません。

誰かがこれについて私を導くことができますか?

4

1 に答える 1

2

答えが見つかりました: iOS 開発者ライブラリで適切に文書化されています: http://developer.apple.com/library/ios/#samplecode/QuickContacts/Listings/Classes_QuickContactsViewController_m.html#//apple_ref/doc/uid/DTS40009475-Classes_QuickContactsViewController_m-DontLinkElementID_6

以下は、ABPersonRecordRef をオブジェクトとして返すために実装したサンプル コードです。私が経験したエラーは、返された後に ABPersonRecordRef オブジェクトを保持しないことに関連していました。

- (id)personRecordUsingModelObj:(id)modelObj {
    ABRecordRef aContact = ABPersonCreate();
    CFErrorRef anError = NULL;

    NSString *name = [NSString stringWithFormat:@"%@", [modelObj name]];
    ABRecordSetValue(aContact, kABPersonOrganizationProperty, name, &anError);  

    ABMultiValueRef phone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(phone, [modelObj phone], kABPersonPhoneMainLabel, NULL);

    ABRecordSetValue(aContact, kABPersonPhoneProperty, phone, &anError);
    CFRelease(phone);

    NSString *address = [NSString stringWithFormat:@"%@ %@", [modelObj addr1], [modelObj addr2]];
    NSMutableDictionary *dictionaryAddress = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dictionaryAddress setObject:address forKey:(NSString *)kABPersonAddressStreetKey];
    [dictionaryAddress setObject:@"us" forKey:(NSString *)kABPersonAddressCountryCodeKey];

    ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABDictionaryPropertyType);
    ABMultiValueAddValueAndLabel(address, dictionaryAddress, kABPersonAddressStreetKey, NULL);
    [dictionaryAddress release];

    ABRecordSetValue(aContact, kABPersonAddressProperty, address, &anError);
    CFRelease(address); 

    if (anError) {
        aContact = nil;
    }

    [(id)aContact autorelease];

    return (id)aContact;
}
于 2011-04-26T13:37:29.347 に答える