1

会社の詳細をデバイスの電話帳に追加するボタンを実装しました。詳細を追加すると、連絡先画面から再びアプリに戻ることができなくなります。ホームボタンを押してからアプリを再起動する必要があります。ここで基本的な何かが欠けているに違いない

   ABUnknownPersonViewController *unknownPersonViewController = [[ABUnknownPersonViewController alloc] init];
unknownPersonViewController.displayedPerson = (ABRecordRef)[self buildContactDetails];
unknownPersonViewController.allowsAddingToAddressBook = YES;
[self.navigationController pushViewController:unknownPersonViewController animated:YES];

}

- (ABRecordRef)buildContactDetails {
NSLog(@"building contact details");
ABRecordRef person = ABPersonCreate();
CFErrorRef  error = NULL;




//Contact picture
NSData *dataRef = UIImagePNGRepresentation(contact.image); 
ABPersonSetImageData(person, (__bridge_retained CFDataRef)dataRef, nil);


// Name
ABRecordSetValue(person, kABPersonFirstNameProperty, @"Don Juan", NULL);



//Phone number

ABMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiRealPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, (__bridge_retained CFStringRef)@"0000000000", kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, multiPhone, nil);
CFRelease(multiPhone);


// email
ABMutableMultiValueRef email = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(email, @"hotmail.com", CFSTR("email"), NULL);
ABRecordSetValue(person, kABPersonEmailProperty, email, &error);
CFRelease(email);

// Start of Address
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDict = [[NSMutableDictionary alloc] init];
[addressDict setObject:@"High Street" forKey:(NSString *)kABPersonAddressStreetKey];
[addressDict setObject:@"0000" forKey:(NSString *)kABPersonAddressZIPKey];
[addressDict setObject:@"00000" forKey:(NSString *)kABPersonAddressCityKey];
ABMultiValueAddValueAndLabel(address,(__bridge_retained CFDataRef) addressDict,  kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonAddressProperty, address, &error);


// End of Address

if (error != NULL)
    NSLog(@"Error: %@", error);


return person;
}
4

1 に答える 1

0

これを試して :

した後presentModalViewController

のためにABPersonViewController *view

あなたはすべきですdismissModalViewControllerAnimated

于 2012-12-23T13:49:14.450 に答える