3

Is it possible to add CardDav account programmatically as it can be done by manually using Mail,Contacts,Calendras -> Add Account option in Settings app.

In general is it possible to add in code any other type of acccount?

For instance exchange account. I read that somewhere on forum that it isn't.

According with ABSource it seems that it is not possible to add account from the code. There are just functions for reading and copying values from appropriate source record

  • Maybe you should clarify the reason you want to do that / the use case. Could profiles be a solution to your issue? – hnh Jul 10 '14 at 19:22
  • Sure, in my case I have a CardDav server. If I add CardDAV's account from the code, then the standard app- Contacts will be able to get list of contacts from CardDAV and transfer it to my address book, or there might be some background services that will add contacts to my address book. Otherwise, I will have to ask server for a list of records, and download them (download vCards). – Siarhei Yakushevich Jul 10 '14 at 20:16

1 Answers1

4

Yes, you can create a "configuration profile": a plist in which you can specify the CardDav account profile. You can find info about the format on the Apple Documentation under Card Dav payload.

Here is an example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Inc//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>PayloadVersion</key>
    <integer>1</integer>

    <key>PayloadUUID</key>
    <string>randomUUID</string>

    <key>PayloadType</key>
    <string>Configuration</string>

    <key>PayloadIdentifier</key>
    <string>com.example.carddav</string>

    <key>Label</key>
    <string>A Carddav Profile</string>

    <key>PayloadContent</key>
    <array>
    <dict>

        <key>CardDAVAccountDescription</key>
        <string>A Carddav Description</string>

        <key>CardDAVHostName</key>
        <string>carddav.example.com</string>

        <key>CardDAVPrincipalURL</key>
        <string>/principals/userid/</string>

        <key>CardDAVUsername</key>
        <string>userId</string>

        <key>CardDAVPassword</key>
        <string>password</string>

        <key>PayloadDescription</key>
        <string>Configures CardDAV account</string>

        <key>PayloadIdentifier</key>
        <string>com.example.carddav</string>

        <key>PayloadOrganization</key>
        <string>A nice company</string>

        <key>PayloadType</key>
        <string>com.apple.carddav.account</string>

        <key>PayloadUUID</key>
        <string>randomUUID</string>

       <key>PayloadVersion</key>
       <integer>1</integer>
    </dict>
    </array>
</dict>
</plist>

Remember to save the file with ".mobileconfig". extension.

Then if you are interested on how you can open a configuration profile programmatically, you can look at this question https://stackoverflow.com/questions/2338035/installin g-a-configuration-profile-on-iphone-programmatically

Community
  • 1
  • 1
andreacipriani
  • 2,519
  • 26
  • 23