0

How do I get access to the externalIdentifier of a CNContainer object?

externalIdentifier is not an instance property of the CNContainer object. I printed to the debug window the description property of a CNContainer object. I show that below, with "externalIdentifier" in bold.

<CNContainer: 0x2829a43f0: identifier=32B14F4B-7299-4AA5-BADD-85344DB3D7B8, name=Contacts, type=3 ( CardDAV ), iOSLegacyIdentifier=1346, accountIdentifier=012AF8C6-A3AB-4AD6-8C91-5FB5266CC8E6, enabled=1, permissions=<CNContainerPermissions: 0x2819a21e0: canCreateContacts=NO, canDeleteContacts=NO, canCreateGroups=NO>, externalIdentifier=/dav/brenebrownfan/Contacts/, externalModificationTag=c7e1249ffc03eb9ded908c236bd1996d, externalSyncTag=(nil), externalSyncData={length = 95, bytes = 0x62706c69 73743030 d2010203 045e6d61 ... 00000000 0000003a }, constraintsPath=(nil), meIdentifier=635, restrictions=0, guardianRestricted=0, lastSyncDate=2019-09-25 08:14:59 +0000>

daniel
  • 1,446
  • 3
  • 29
  • 65
  • 1
    Since there is no public API for that there is no official way to get this information. https://developer.apple.com/documentation/contacts/cncontainer – Stefan Wieland Feb 02 '22 at 15:53

1 Answers1

1

Swift:

let externalIdentifier = container.value(forKey: "externalIdentifier") as? String

Objective-C:

NSString *externalIdentifier = [container valueForKey:@"externalIdentifier"];

Thomas Verbeek
  • 2,361
  • 28
  • 30
  • Ok. Good. I tried that and it works. This must mean I can access other "properties" this way. If you know how I can figure where the Contacts that are in iCloud are, I would like to know. I'm not sure if it would be a single CNContainer and if it would say "iCloud" in one of the "properties" I can access using .value(forKey:). – daniel Jul 26 '22 at 06:27