B4i Library iContacts + ContactsUtils - Read and write to the contacts store

Discussion in 'iOS Libraries' started by Erel, Feb 22, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User

    ContactsUtils is a class that together with iContacts library, provide read and write access to the device contacts store.

    Note that it is based on the new Contacts framework introduced in iOS 9. So your project should include:
    #MinVersion: 9

    The first method that you will usually call is ContactsUtils.GetContacts. It will asynchronously read all contacts and raise the Available event when the data is available.
    By default it will only fetch the name related fields. You can pass an array with additional keys that should be fetched for all contacts.
    You can later access more fields but it will be slower as it will need to get the fields from the device store.

    Example of filling a TableView with the contacts names and first phone number:
    Private Sub cutils_Available (Success As Boolean, Contacts As List)
    If Success = False Then
    Msgbox("Error getting contacts""")
    End If
    For Each cu As cuContact In Contacts
    Dim phones As List = cutils.GetPhones(cu)
    Dim phone As String
    If phones.Size > 0 Then
    Dim cp As cuPhone = phones.Get(0'Each item is a cuPhone type.
           phone = cp.Number
    phone = "N/A"
    End If
    Dim tc As TableCell = TableView1.AddTwoLines(cu.DisplayName, phone)
         tc.Bitmap = cutils.GetPhotoThumbnail(cu)
         tc.Tag = cu
    End Sub
    cuContact, cuPhone, cuEmail and cuDate are custom types declared in ContactsUtils.


    This code taken from the example project creates a new contact and then updates its fields:
    Dim cu As cuContact = cutils.InsertContact("AAJohn""Due")
    Dim phone As cuPhone
    phone.Number = "12345678"
    phone.PhoneType = "Other"
    "Created by B4i")
    LoadBitmap(File.DirAssets, "smiley.gif"))
    You can also update fields of existing contacts.

    Starting from iOS 10 you need to add a usage description such as:
    #PlistExtra:<key>NSContactsUsageDescription</key><string>Select a contact.</string>

    Attached Files:

    Last edited: Nov 9, 2016
    luke2012, Mark Turney, MikeH and 2 others like this.
  2. PalmZac_LYL

    PalmZac_LYL Member Licensed User


    Great Library ! :)
    I want to add/delete contact with new/existing group. How to add/delete Groups in this library ? Would you give me a sample ? Thanks ! ;)
  3. Erel

    Erel Administrator Staff Member Licensed User

    Groups are currently not implemented.
  4. PalmZac_LYL

    PalmZac_LYL Member Licensed User

    OK. I am waiting for next version.
  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