New Release!
v9.6.1 - 2015/11/29
- Fixed Components compile error
Download: D.P.F Delphi iOS Native Components
function TDPFAddressBook.AddAddressBook( FirstName: string; LatName: string; PhoneNumbers: array of TPhoneNumbers ): Boolean; var Person : ABRecordRef; error : CFErrorRef; addressBook : ABAddressBookRef; phoneNumberMultiValue: ABMutableMultiValueRef; venuePhoneNumbers : NSMutableArray; I : Integer; s : string; begin result := false; addressBook := ABAddressBookCreateWithOptions( nil, &error ); Person := ABPersonCreate; if not Assigned( Person ) then exit; // FirsName & LastName result := ABRecordSetValue( Person, 0, PNSSTR( FirstName ), &error ); if not result then exit; result := ABRecordSetValue( Person, 1, PNSSTR( LatName ), &error ); if not result then exit; result := ABAddressBookAddRecord( addressBook, Person, &error ); if not result then exit; // Phone phoneNumberMultiValue := ABMultiValueCreateMutable( kABMultiStringPropertyType ); for I := low( PhoneNumbers ) to high( PhoneNumbers ) do begin if PhoneNumbers[I].PhoneLabel = '' then PhoneNumbers[I].PhoneLabel := kABPersonPhoneMainLabel; ABMultiValueAddValueAndLabel( phoneNumberMultiValue, PNSSTR( PhoneNumbers[I].PhoneNumber ), CFSTR( PhoneNumbers[I].PhoneLabel ), 0 ); end; result := ABRecordSetValue( person, 3, phoneNumberMultiValue, nil ); CFRelease( phoneNumberMultiValue ); if not result then exit; // Save to AddressBook if ABAddressBookHasUnsavedChanges( addressBook ) then result := ABAddressBookSave( addressBook, &error ); exit; end;
procedure TFPeoplePicker.DPFAddressBook1RequestAccess( Sender: TObject; const Granted: Boolean ); var p: array [0 .. 2] of TPhoneNumbers; begin P[0].PhoneNumber := '+98912xxxxx'; P[0].PhoneLabel := 'mobile'; P[1].PhoneNumber := '+982188xxxxx'; P[1].PhoneLabel := 'work'; P[2].PhoneNumber := '+982188xxxxx'; P[2].PhoneLabel := ''; // <-- contact’s primary number if Granted then DPFAddressBook1.AddAddressBook( 'Babak', 'Yaghoobi', p ) else ShowMessage( 'Go to Setting->Privacy->Contacts and switch on this application' ); end;Enjoy Delphi iOS Native Programming !
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>PreferenceSpecifiers</key> <array> <dict> <key>Title</key> <string>D.P.F iOS Native Components</string> <key>Type</key> <string>PSGroupSpecifier</string> <key>FooterText</key> <string>Copyright, 2013-2015 D.P.F.
All rights reserved.</string> </dict> <dict> <key>DefaultValue</key> <string>7.9.5</string> <key>Key</key> <string>version_preference</string> <key>Title</key> <string>Version</string> <key>Type</key> <string>PSTitleValueSpecifier</string> </dict> <dict> <key>DefaultValue</key> <string>Babak Yaghoobi</string> <key>Key</key> <string>developed_preference</string> <key>Title</key> <string>Developed by</string> <key>Type</key> <string>PSTitleValueSpecifier</string> </dict> <dict> <key>DefaultValue</key> <string>bayaghoobi@gmail.com</string> <key>Key</key> <string>developed_preference</string> <key>Title</key> <string>eMail : </string> <key>Type</key> <string>PSTitleValueSpecifier</string> </dict> <dict> <key>DefaultValue</key> <string>Babak Yaghoobi</string> <key>Key</key> <string>Enabled_preference</string> <key>Title</key> <string>Enabled</string> <key>Type</key> <string>PSToggleSwitchSpecifier</string> </dict> </array> <key>StringsTable</key> <string>Root</string> </dict> </plist>