私はXcodeを初めて使用し、アプリでアドレスブックにアクセスして人を選択し、その人のNSString値(名、姓、組織、住所、電子メール、電話番号)を作成しようとしています。姓名、組織、入力された最初の電子メール(すべての電子メールアドレスを表示し、ユーザーに選択させると便利です)、および入力された最初の電話番号(ここでも、選択する)が、その人の住所は常に空白です。私はあなたが提供できるどんな助けでも本当に感謝します。さらに、ローカル宣言がインスタンス変数の警告を非表示にし続けます-これらを解決する方法がわかりません。
#import "TACustomer.h"
@interface TACustomer ()
@end
@implementation TACustomer
@synthesize custfirstName;
@synthesize custlastName;
@synthesize custOrganization;
@synthesize custEmail;
@synthesize custAddress;
@synthesize custphoneNumber;
- (IBAction)showPicker:(id)sender
{
// Creating the Address Book Picker
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
// Place the delegate of the picker to the control.
picker.peoplePickerDelegate = self;
// Showing the picker.
[self presentModalViewController:picker animated:YES];
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
//assigning control back to the main controller.
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
[self displayPerson:person];
[self dismissModalViewControllerAnimated:YES];
return NO;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
// Only inspect the value if it's an address.
if (property == kABPersonAddressProperty)
{
//Set up an ABMultiValue to hold the address values; copy from a book record.
ABMutableMultiValueRef multicustValue = ABRecordCopyValue(person, property);
// Set up an NSArray and copy values into it.
NSArray *thecustArray = (__bridge id)ABMultiValueCopyArrayOfAllValues(multicustValue);
// Figure out which values we want and store the index.
const NSUInteger customerIndex = ABMultiValueGetIndexForIdentifier (multicustValue, identifier);
// Set up an NSDictionary to hold the contents of the array.
NSDictionary *custDict = [thecustArray objectAtIndex:customerIndex];
// Set up NSStrings to hold the keys and values. First, how many are there?
const NSUInteger theCount = [custDict count];
NSString * __unsafe_unretained keys[theCount];
NSString *__unsafe_unretained values[theCount];
// Get the keys and values from the CFDictionary.
[custDict getObjects:values andKeys:keys];
// Set the address label's text.
NSString *customeraddress;
customeraddress = [NSString stringWithFormat:@"%@, %@, %@, %@, %@",
[custDict objectForKey:(NSString *)kABPersonAddressStreetKey],
[custDict objectForKey:(NSString *)kABPersonAddressCityKey],
[custDict objectForKey:(NSString *)kABPersonAddressStateKey],
[custDict objectForKey:(NSString *)kABPersonAddressZIPKey],
[custDict objectForKey:(NSString *)kABPersonAddressCountryKey]];
self.custAddress.text = customeraddress;
}
return NO;
}
- (void)displayPerson:(ABRecordRef)person
{
// Get Customer First Name
NSString* custfirstname = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonFirstNameProperty);
self.custfirstName.text = custfirstname;
// Get Customer Last Name
NSString* custlastname = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonLastNameProperty);
self.custlastName.text = custlastname;
// Get Customer Organization
NSString* custorganization = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonOrganizationProperty);
self.custOrganization.text = custorganization;
//Get Customer Email Address
NSString* custemail = nil;
ABMultiValueRef custemailAddresses = ABRecordCopyValue (person,kABPersonEmailProperty);
if (ABMultiValueGetCount(custemailAddresses) > 0)
{
custemail = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(custemailAddresses, 0);
} else
{
custemail = @"[None]";
}
self.custEmail.text = custemail;
CFRelease(custemailAddresses);
// Get Customer Phone Number
NSString* custphone = nil;
ABMultiValueRef phoneNumbers = ABRecordCopyValue (person,kABPersonPhoneProperty);
if (ABMultiValueGetCount(phoneNumbers) > 0)
{
custphone = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
} else
{
custphone = @"[None]";
}
self.custphoneNumber.text = custphone;
CFRelease(phoneNumbers);
bundle:nil;
//[self.navigationController pushViewController:tempExamInfoView animated:YES];
}
@end