Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Adding programmatically CardDAV account

Tags:

ios

carddav

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

like image 332
Siarhei Yakushevich Avatar asked Dec 06 '25 03:12

Siarhei Yakushevich


1 Answers

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

like image 132
andreacipriani Avatar answered Dec 07 '25 20:12

andreacipriani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!