iOS Question AddressBook OBJC

narek adonts

Well-Known Member
Licensed User
Hi

here is the short OBJC code to get all contacts

B4X:
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, nil);
NSArray *allContacts = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBookRef);

i am doing

B4X:
#If OBJC
- (NSArray *) GC
{

ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, nil);
NSArray *allContacts = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBookRef);
return allContacts;
}


#End if



Dim jo As NativeObject = Me
Dim l As List=jo.GetField("GC")
but it doesnt work. it says [<b4i_main 0x1700f6380> valueForUndefinedKey:]: this class is not key value coding-compliant for the key GC.

how can I use native object to retunr this to a list

Narek
 
Last edited:

narek adonts

Well-Known Member
Licensed User
B4X:
@import AddressBook;

- (NSArray *) GC
{

ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, nil);
NSArray *allContacts = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBookRef);
return allContacts;
}
B4X:
Dim no As NativeObject = Me
Dim l As List=    no.RunMethod("GC", Array(Null))
 

Brian Robinson

Active Member
Licensed User
I have started a quick bit of work on building a Contacts class. It is just from the shell of what has been found on the internet.

I just wanted to post this here as I have not written a lib/class before and wasn't sure what I am doing is the write way to do it.

When getting the allContacts NSArray before, it returned a list of ABPerson items. I had no idea how to access them. So I have written a wrapper to turn them into something usable in B4i, but I am not sure if this is the correct way of doing things as it is double handling the data. Any one that can guide me on how it should be done I would appreciate it.

I have put an example of it in this post. http://www.b4x.com/android/forum/th...dress-book-iphone-contacts.52118/#post-327208

Oh yeah - and how much do I dislike Obj-C... This is why I am so glad Erel has provided us with B4i... I could not program in this language every day.

Feedback please?

Cheers
Brian
 

Brian Robinson

Active Member
Licensed User
No, that's ok...

If you have already finished it then I don't need to write it. Thanks for letting me know.

Cheers
Brian
 
Top