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
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
来源:https://stackoverflow.com/questions/24671870/ios-adding-programmatically-carddav-account