Mega Search
23.2 Million


Sign Up

Make a donation  
Creating a new address book contact in iOS  
News Group: embarcadero.public.delphi.platformspecific.ios

I'm trying to create a new address book contact in iOS using XE 7 and I think I'm on the right track, but I'm stuck with code around ABMultiValueAddValueAndLabel as I can't seem to find an examples anywhere using Delphi.

Its the first work direct with the iOS API I've done, so whilst I've done lots of WinAPI stuff over the years (stretching back to delphi 1), iOS is new to me.

I've found some objective C code that I'm attempting to base the code off (http://snipplr.com/view/33957/) and this is what I've got so far...

(I'm also using the DPF iOS native library at the moment to help, but plan to strip out what I need at a later date, once I've got it working, as I don't need the entire thing, just the API wrappers)

Procedure TContactManager.AddContact(aNumber, aName : String);
Var
  addressBook   : ABAddressBookRef;
  person : ABRecordRef;
  error  : CFErrorRef;
  nsName,
  nsNumber : TNSString;
  abPhone : ABMultiValueRef;

Begin
  nsName := NSSTR(aName);
  nsNumber := NSSTR(aNumber);

  addressBook    := ABAddressBookCreateWithOptions( nil, error );
  person  := ABPersonCreate;
  ABRecordSetValue(person,kABPersonOrganizationProperty,nsName,error);

  abPhone := ABMultiValueCreateMutable(kABMultiStringPropertyType);
// ABMultiValueCreateMutable isn't resolved

{ - IOS Code
		ABMultiValueAddValueAndLabel(abPhone, venue.phone, kABPersonPhoneMainLabel, NULL);
		ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
		ABMultiValueAddValueAndLabel(multiPhone, venue.phone, kABPersonPhoneMainLabel, NULL);
		ABRecordSetValue(person, kABPersonPhoneProperty, multiPhone, &error);
		CFRelease(multiPhone);
}
	
End;

I don't like asking for people to write code for me, but I'm stuck and against a deadline :( Any help would be very much appreciated, I presume the above is enough to add a name and a number into the contact book, please let me know if its not.

If anyone is interested, I've got working code for Android I could do swapsies with! ;)

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 26-Nov-2014, at 3:54 PM EST
From: Steve Childs