iOS Question AddressBook OBJC

Discussion in 'iOS Questions' started by narek adonts, Mar 24, 2015.

  1. narek adonts

    narek adonts Well-Known Member Licensed User

    Hi

    here is the short OBJC code to get all contacts

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

    i am doing

    Code:
    #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: Mar 24, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is not a field. You need to call jo.RunMethod.
     
  3. narek adonts

    narek adonts Well-Known Member Licensed User

    with RunMethod it is also giving an error

    -[NSMethodSignature getArgumentTypeAtIndex:]: index (2) out of bounds [0, 1]
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Please post the relevant code.
     
  5. narek adonts

    narek adonts Well-Known Member Licensed User

    Code:
    @import AddressBook;

    - (NSArray *) GC
    {

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

    Erel Administrator Staff Member Licensed User

    Your code is passing a parameter to GC (with the value of null).

    It should be:
    no.RunMethod("GC", null)
     
  7. narek adonts

    narek adonts Well-Known Member Licensed User

    Erel,

    Please let us know if you are working on a PhoneBook Library or no to be able to know if it is worth to spend time on creating this library by ourselves.

    Narek
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Eventually there will be a contacts library. However it will not happen in the near future.
     
  9. Brian Robinson

    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
     
  10. narek adonts

    narek adonts Well-Known Member Licensed User

    I have already finished the Contacts class. Will publish today. You can work on it after.

    Narek
     
  11. Brian Robinson

    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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice