私の iPhone アプリでは、持っている vCard をクリックしたときに、vCard を iPhone の連絡先に保存したいと考えています。
どうやってやるの?
これを行うアプリをアプリストアで見ました:
http://itunes.apple.com/us/app/read-vcard/id402216831?mt=8
ありがとう
私の iPhone アプリでは、持っている vCard をクリックしたときに、vCard を iPhone の連絡先に保存したいと考えています。
どうやってやるの?
これを行うアプリをアプリストアで見ました:
http://itunes.apple.com/us/app/read-vcard/id402216831?mt=8
ありがとう
iOS9 で導入された新しい連絡先フレームワークにより、vCard データを iPhone の連絡先に保存することは、Swift4 を使用するとはるかに簡単かつシンプルになります。
import Contacts
func saveVCardContacts (vCard : Data) { // assuming you have alreade permission to acces contacts
if #available(iOS 9.0, *) {
let contactStore = CNContactStore()
do {
let saveRequest = CNSaveRequest() // create saveRequests
let contacts = try CNContactVCardSerialization.contacts(with: vCard) // get contacts array from vCard
for person in contacts{
saveRequest.add(person as! CNMutableContact, toContainerWithIdentifier: nil) // add contacts to saveRequest
}
try contactStore.execute(saveRequest) // save to contacts
} catch {
print("Unable to show the new contact") // something went wrong
}
}else{
print("CNContact not supported.") //
}
}
以下は、 にユーザー情報を追加するためのコードですiPhone's Contact
。
については何も知らないと言いましたが、マリノアが投稿しvCard
たこのコードは、こちらの回答で役立つ場合があります。
ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book record
ABRecordRef person = ABPersonCreate(); // create a person
NSString *phone = @"0123456789"; // the phone number to add
//Phone number is a list of phone number, so create a multivalue
ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABPersonPhoneProperty);
ABMultiValueAddValueAndLabel(phoneNumberMultiValue ,phone,kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(person, kABPersonFirstNameProperty, @"FirstName" , nil); // first name of the new person
ABRecordSetValue(person, kABPersonLastNameProperty, @"LastName", nil); // his last name
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, &anError); // set the phone number property
ABAddressBookAddRecord(addressBook, person, nil); //add the new person to the record
ABRecordRef group = ABGroupCreate(); //create a group
ABRecordSetValue(group, kABGroupNameProperty,@"My Group", &error); // set group's name
ABGroupAddMember(group, person, &error); // add the person to the group
ABAddressBookAddRecord(addressBook, group, &error); // add the group
ABAddressBookSave(addressBook, nil); //save the record
CFRelease(person); // relase the ABRecordRef variable
コーディングのお手伝いはできませんが、以前の投稿で vCard の一般的なフォーマットを見つけました。この形式を使用してタスクを達成することができます。左側の値は常に静的です。そんな使い方ができれば幸いです。
参考までに、グーグルを見つけました...(3つのモバイルプラットフォームすべてをサポート)
http://learnyii.blogspot.com/2011/04/vcard-qr-code-iphone-android-blackberry.html
ABMutableMultiValueRef date = ABRecordCopyValue(newPerson, kABPersonDateProperty);
ABMultiValueAddValueAndLabel(date, dateTextField.text, kABPersonAnniversaryLabel, NULL);
ABRecordSetValue(newPerson, kABPersonDateProperty, date,nil);