@capacitor/contacts 1.0.2-next.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,8 +38,9 @@ Notes:
38
38
  - The plugin uses the modern **Contacts framework** (`CNContactStore`,
39
39
  never the deprecated AddressBook APIs), so it fully supports iOS 18+
40
40
  **Limited Access**: `find`, `save` and `remove` operate on the subset the
41
- user shared with the app, and `pickContact` presents the system picker
42
- (which needs no permission and always shows the full contact list).
41
+ user shared with the app, while `pickContact` and `pickContactField` present
42
+ the system picker (which needs no permission and always shows the full
43
+ contact list).
43
44
  - The `note` field is not supported on iOS: reading or writing it requires
44
45
  Apple's restricted `com.apple.developer.contacts.notes` entitlement. The
45
46
  field is omitted on read and ignored on save.
@@ -52,13 +53,41 @@ The plugin declares `READ_CONTACTS` and `WRITE_CONTACTS` in its own
52
53
  manifest; Gradle manifest merging adds them to your app automatically. Each
53
54
  method requests the runtime permission it needs the first time it runs;
54
55
  read for `find`/`pickContact`, read + write for `save`/`remove`.
56
+ The `pickContactField` method needs no permission: it opens the contacts app on a single
57
+ data kind (phone, email or address), and the app grants temporary read access
58
+ to just the row the user selects.
59
+
60
+ :::warning[Google Play Requirements]
61
+
62
+ The `pickContactField` method exists mainly to adhere to Google Play's restrictions for the Contacts Permission. This only applies to apps using Capacitor 9 or higher. You should evaluate whether `pickContactField` is enough for your app's use cases. If not, you may need to submit a Play Console declaration. For more information refer to [Google Play's page](https://support.google.com/googleplay/android-developer/answer/16909972?sjid=14458661934730177096-EU#contacts-permissions).
63
+
64
+ :::
65
+
66
+ If your app only uses `pickContactField`, you can keep the contacts
67
+ permissions out of your app by removing them from the merged manifest in your
68
+ app's `AndroidManifest.xml`:
69
+
70
+ ```xml
71
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
72
+ xmlns:tools="http://schemas.android.com/tools">
73
+
74
+ <uses-permission android:name="android.permission.READ_CONTACTS" tools:node="remove" />
75
+ <uses-permission android:name="android.permission.WRITE_CONTACTS" tools:node="remove" />
76
+ </manifest>
77
+ ```
78
+
79
+ The other methods then reject with `OS-PLUG-CONT-0021`, because the
80
+ permissions they need are not declared.
55
81
 
56
82
  ## Permission model
57
83
 
58
84
  This plugin intentionally exposes **no** `checkPermissions()` /
59
85
  `requestPermissions()` methods: permissions are requested implicitly by each
60
86
  method, matching the legacy `cordova-plugin-contacts` behavior. A call
61
- rejects with `OS-PLUG-CONT-0020` when the user denies access.
87
+ rejects with `OS-PLUG-CONT-0020` when the user denies access. `pickContactField`
88
+ needs no permission. On Android, the other methods reject with
89
+ `OS-PLUG-CONT-0021` when the permissions they need are not declared in the
90
+ app's manifest.
62
91
 
63
92
  ## Errors
64
93
 
@@ -74,6 +103,7 @@ Every rejection carries a structured code + message:
74
103
  | `OS-PLUG-CONT-0005` | Not supported |
75
104
  | `OS-PLUG-CONT-0006` | Operation cancelled (picker closed) |
76
105
  | `OS-PLUG-CONT-0020` | Permission denied |
106
+ | `OS-PLUG-CONT-0021` | Required permission not declared in the Android manifest |
77
107
 
78
108
  ## Usage
79
109
 
@@ -100,9 +130,12 @@ const saved = await Contacts.save({
100
130
  // Update it (id present -> update)
101
131
  await Contacts.save({ contact: { ...saved, nickname: 'Countess' } });
102
132
 
103
- // Pick a contact with the native picker
133
+ // Pick a contact with the native picker; needs contacts permission on Android
104
134
  const picked = await Contacts.pickContact();
105
135
 
136
+ // Pick a single phone number, email or address; needs no contacts permission on both platforms
137
+ const { value, type, displayName } = await Contacts.pickContactField({ field: 'phone' });
138
+
106
139
  // Remove it by id
107
140
  await Contacts.remove({ id: saved.id! });
108
141
  ```
@@ -115,6 +148,7 @@ await Contacts.remove({ id: saved.id! });
115
148
  * [`save(...)`](#save)
116
149
  * [`remove(...)`](#remove)
117
150
  * [`pickContact()`](#pickcontact)
151
+ * [`pickContactField(...)`](#pickcontactfield)
118
152
  * [Interfaces](#interfaces)
119
153
  * [Type Aliases](#type-aliases)
120
154
 
@@ -219,6 +253,31 @@ contact's details.
219
253
  --------------------
220
254
 
221
255
 
256
+ ### pickContactField(...)
257
+
258
+ ```typescript
259
+ pickContactField(options: PickContactFieldOptions) => Promise<PickedContactField>
260
+ ```
261
+
262
+ Launches the native contact picker UI, showing only the requested kind of
263
+ information, and resolves with the single value the user selects (not a
264
+ full contact). Rejects with `OS-PLUG-CONT-0006` if the user cancels.
265
+
266
+ Needs no contacts permission on either platform, which lets Android apps
267
+ omit READ_CONTACTS from their manifest. Only one data kind can be picked
268
+ per call.
269
+
270
+ | Param | Type |
271
+ | ------------- | --------------------------------------------------------------------------- |
272
+ | **`options`** | <code><a href="#pickcontactfieldoptions">PickContactFieldOptions</a></code> |
273
+
274
+ **Returns:** <code>Promise&lt;<a href="#pickedcontactfield">PickedContactField</a>&gt;</code>
275
+
276
+ **Since:** 1.1.0
277
+
278
+ --------------------
279
+
280
+
222
281
  ### Interfaces
223
282
 
224
283
 
@@ -343,6 +402,43 @@ Options accepted by {@link ContactsPlugin.remove}.
343
402
  | **`id`** | <code>string</code> | The native id of the contact to remove. | 1.0.0 |
344
403
 
345
404
 
405
+ #### PickedContactField
406
+
407
+ The value the user picked with {@link ContactsPlugin.pickContactField}. This is
408
+ not a full contact: it holds only the picked value, its label and the
409
+ contact's display name.
410
+
411
+ | Prop | Type | Description | Since |
412
+ | ----------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ----- |
413
+ | **`field`** | <code>'phone' \| 'email' \| 'address'</code> | The kind of value that was picked, as requested. | 1.1.0 |
414
+ | **`value`** | <code>string</code> | The picked phone number, email address, or postal address formatted for display, depending on `field`. | 1.1.0 |
415
+ | **`type`** | <code>string</code> | The label of the picked value, e.g. `mobile`, `home`, `work`. | 1.1.0 |
416
+ | **`displayName`** | <code>string</code> | The display name of the contact the value belongs to, when available. | 1.1.0 |
417
+ | **`address`** | <code><a href="#pickedcontactaddress">PickedContactAddress</a></code> | The parts of the postal address. Only present when `field` is `address`. | 1.1.0 |
418
+
419
+
420
+ #### PickedContactAddress
421
+
422
+ The parts of a postal address returned by {@link ContactsPlugin.pickContactField}.
423
+
424
+ | Prop | Type | Description | Since |
425
+ | ------------------- | ------------------- | --------------------- | ----- |
426
+ | **`streetAddress`** | <code>string</code> | The street address. | 1.1.0 |
427
+ | **`locality`** | <code>string</code> | The city or locality. | 1.1.0 |
428
+ | **`region`** | <code>string</code> | The state or region. | 1.1.0 |
429
+ | **`postalCode`** | <code>string</code> | The postal code. | 1.1.0 |
430
+ | **`country`** | <code>string</code> | The country. | 1.1.0 |
431
+
432
+
433
+ #### PickContactFieldOptions
434
+
435
+ Options accepted by {@link ContactsPlugin.pickContactField}.
436
+
437
+ | Prop | Type | Description | Since |
438
+ | ----------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------- | ----- |
439
+ | **`field`** | <code>'phone' \| 'email' \| 'address'</code> | The single kind of contact information to pick. Any other value rejects with `OS-PLUG-CONT-0001`. | 1.1.0 |
440
+
441
+
346
442
  ### Type Aliases
347
443
 
348
444
 
@@ -0,0 +1,17 @@
1
+ package com.capacitorjs.plugins.contacts
2
+
3
+ import android.net.Uri
4
+ import android.provider.ContactsContract.CommonDataKinds.Email
5
+ import android.provider.ContactsContract.CommonDataKinds.Phone
6
+ import android.provider.ContactsContract.CommonDataKinds.StructuredPostal
7
+
8
+ /** The single data kind a `pickContactField` call lets the user pick. */
9
+ enum class ContactPickableField(val key: String, val contentUri: Uri) {
10
+ PHONE("phone", Phone.CONTENT_URI),
11
+ EMAIL("email", Email.CONTENT_URI),
12
+ ADDRESS("address", StructuredPostal.CONTENT_URI);
13
+
14
+ companion object {
15
+ fun fromKey(key: String?): ContactPickableField? = values().firstOrNull { it.key == key }
16
+ }
17
+ }
@@ -220,6 +220,71 @@ class Contacts(private val context: Context) {
220
220
  return null
221
221
  }
222
222
 
223
+ /**
224
+ * Reads the single data row returned by an `ACTION_PICK` on [kind]'s
225
+ * data-kind URI into a `pickContactField` result: the picked `value` and
226
+ * its `type` label, plus the contact's `displayName` when available.
227
+ * Picking a specific data-kind URI instead of the generic
228
+ * `Contacts.CONTENT_URI` makes the device's contacts app delegate
229
+ * temporary read permission on just that row, so no READ_CONTACTS
230
+ * permission is needed.
231
+ *
232
+ * @param kind the data kind that was requested from the picker.
233
+ * @param pickedUri the URI of the row the contacts app returned.
234
+ * @return the result with `field`, `value`, `type`, `displayName` (when
235
+ * known) and, for addresses, `address`; null if the row is gone or holds
236
+ * no value.
237
+ * @throws SecurityException if the provider refuses to read the row.
238
+ */
239
+ fun readPickedField(kind: ContactPickableField, pickedUri: Uri): JSObject? {
240
+ val projection = arrayOf(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY) + when (kind) {
241
+ ContactPickableField.PHONE -> arrayOf(Phone.NUMBER, Phone.TYPE, Phone.LABEL)
242
+ ContactPickableField.EMAIL -> arrayOf(Email.ADDRESS, Email.TYPE, Email.LABEL)
243
+ ContactPickableField.ADDRESS -> arrayOf(
244
+ StructuredPostal.FORMATTED_ADDRESS, StructuredPostal.STREET, StructuredPostal.CITY,
245
+ StructuredPostal.REGION, StructuredPostal.POSTCODE, StructuredPostal.COUNTRY,
246
+ StructuredPostal.TYPE, StructuredPostal.LABEL
247
+ )
248
+ }
249
+
250
+ context.contentResolver.query(pickedUri, projection, null, null, null)?.use { cursor ->
251
+ if (!cursor.moveToFirst()) return null
252
+ fun str(name: String): String? {
253
+ val i = cursor.getColumnIndex(name)
254
+ return if (i >= 0) cursor.getString(i) else null
255
+ }
256
+ fun int(name: String): Int {
257
+ val i = cursor.getColumnIndex(name)
258
+ return if (i >= 0) cursor.getInt(i) else -1
259
+ }
260
+
261
+ val result = JSObject()
262
+ result.put("field", kind.key)
263
+ when (kind) {
264
+ ContactPickableField.PHONE -> {
265
+ result.put("value", str(Phone.NUMBER) ?: return null)
266
+ result.put("type", phoneLabel(int(Phone.TYPE), str(Phone.LABEL)))
267
+ }
268
+
269
+ ContactPickableField.EMAIL -> {
270
+ result.put("value", str(Email.ADDRESS) ?: return null)
271
+ result.put("type", emailLabel(int(Email.TYPE), str(Email.LABEL)))
272
+ }
273
+
274
+ ContactPickableField.ADDRESS -> {
275
+ result.put("value", str(StructuredPostal.FORMATTED_ADDRESS) ?: return null)
276
+ result.put("type", addressLabel(int(StructuredPostal.TYPE), str(StructuredPostal.LABEL)))
277
+ val address = JSObject()
278
+ putAddressParts(address, ::str)
279
+ result.put("address", address)
280
+ }
281
+ }
282
+ str(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY)?.let { result.put("displayName", it) }
283
+ return result
284
+ }
285
+ return null
286
+ }
287
+
223
288
  private fun wants(field: String, desiredFields: Set<String>): Boolean =
224
289
  desiredFields.isEmpty() || desiredFields.contains(field)
225
290
 
@@ -307,11 +372,7 @@ class Contacts(private val context: Context) {
307
372
  address.put("pref", pref)
308
373
  address.put("type", addressLabel(int(StructuredPostal.TYPE), str(StructuredPostal.LABEL)))
309
374
  address.put("formatted", str(StructuredPostal.FORMATTED_ADDRESS))
310
- address.put("streetAddress", str(StructuredPostal.STREET))
311
- address.put("locality", str(StructuredPostal.CITY))
312
- address.put("region", str(StructuredPostal.REGION))
313
- address.put("postalCode", str(StructuredPostal.POSTCODE))
314
- address.put("country", str(StructuredPostal.COUNTRY))
375
+ putAddressParts(address, ::str)
315
376
  addresses.put(address)
316
377
  }
317
378
 
@@ -401,6 +462,21 @@ class Contacts(private val context: Context) {
401
462
  return contact
402
463
  }
403
464
 
465
+ /**
466
+ * Puts the postal parts of a StructuredPostal row into [address].
467
+ *
468
+ * @param address the object to fill with `streetAddress`, `locality`,
469
+ * `region`, `postalCode` and `country`.
470
+ * @param str reads a column of the current row, null when it has no value.
471
+ */
472
+ private fun putAddressParts(address: JSObject, str: (String) -> String?) {
473
+ address.put("streetAddress", str(StructuredPostal.STREET))
474
+ address.put("locality", str(StructuredPostal.CITY))
475
+ address.put("region", str(StructuredPostal.REGION))
476
+ address.put("postalCode", str(StructuredPostal.POSTCODE))
477
+ address.put("country", str(StructuredPostal.COUNTRY))
478
+ }
479
+
404
480
  private fun field(id: String?, value: String?, type: String?, pref: Boolean): JSObject {
405
481
  val f = JSObject()
406
482
  if (id != null) f.put("id", id)
@@ -13,7 +13,8 @@ enum class ContactsError(val code: String, val message: String) {
13
13
  IO_ERROR("OS-PLUG-CONT-0004", "An I/O error occurred while accessing contacts."),
14
14
  NOT_SUPPORTED("OS-PLUG-CONT-0005", "The operation is not supported on this device."),
15
15
  OPERATION_CANCELLED("OS-PLUG-CONT-0006", "The operation was cancelled."),
16
- PERMISSION_DENIED("OS-PLUG-CONT-0020", "Contacts permission was denied.")
16
+ PERMISSION_DENIED("OS-PLUG-CONT-0020", "Contacts permission was denied."),
17
+ PERMISSION_NOT_DECLARED("OS-PLUG-CONT-0021", "A required contacts permission is not declared in the app manifest.")
17
18
  }
18
19
 
19
20
  /**
@@ -3,6 +3,7 @@ package com.capacitorjs.plugins.contacts
3
3
  import android.Manifest
4
4
  import android.app.Activity
5
5
  import android.content.Intent
6
+ import android.net.Uri
6
7
  import android.provider.ContactsContract
7
8
  import com.getcapacitor.JSObject
8
9
  import com.getcapacitor.PermissionState
@@ -23,7 +24,14 @@ import java.util.concurrent.Executors
23
24
  * Permission model is **implicit**: there are no `checkPermissions` /
24
25
  * `requestPermissions` methods. Each method ensures the permission it needs
25
26
  * before touching the provider: read for `find`/`pickContact`, read+write
26
- * for `save`/`remove`. All provider work runs off the main thread.
27
+ * for `save`/`remove`. `pickContactField` is the exception and needs no
28
+ * permission: it runs `ACTION_PICK` on a single data-kind URI (phone, email
29
+ * or address) instead of the generic `Contacts.CONTENT_URI`, which makes the
30
+ * device's contacts app delegate temporary read permission on just the
31
+ * selected row. On Android 17+ the system routes the same intent to the new
32
+ * Contacts Picker, so no API-level branching is needed. The tradeoff is that
33
+ * only one data kind can be picked per call. All provider work runs off the
34
+ * main thread.
27
35
  */
28
36
  @CapacitorPlugin(
29
37
  name = "Contacts",
@@ -175,14 +183,55 @@ class ContactsPlugin : Plugin() {
175
183
  private var pickInProgress = false
176
184
 
177
185
  private fun runPickContact(call: PluginCall) {
186
+ startPicker(call, Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI), "pickContactResult")
187
+ }
188
+
189
+ @ActivityCallback
190
+ private fun pickContactResult(call: PluginCall?, result: androidx.activity.result.ActivityResult) {
191
+ handlePickResult(call, result) { uri -> uri.lastPathSegment?.let { implementation.getContactById(it) } }
192
+ }
193
+
194
+ // ------------------------------------------------------------------
195
+ // pickContactField
196
+ // ------------------------------------------------------------------
197
+
198
+ @PluginMethod
199
+ fun pickContactField(call: PluginCall) {
200
+ val field = ContactPickableField.fromKey(call.getString("field"))
201
+ if (field == null) {
202
+ reject(call, ContactsError.INVALID_ARGUMENT)
203
+ return
204
+ }
205
+ startPicker(call, Intent(Intent.ACTION_PICK, field.contentUri), "pickContactFieldResult")
206
+ }
207
+
208
+ @ActivityCallback
209
+ private fun pickContactFieldResult(call: PluginCall?, result: androidx.activity.result.ActivityResult) {
210
+ val field = ContactPickableField.fromKey(call?.getString("field"))
211
+ handlePickResult(call, result) { uri -> field?.let { implementation.readPickedField(it, uri) } }
212
+ }
213
+
214
+ // ------------------------------------------------------------------
215
+ // Shared picker flow
216
+ // ------------------------------------------------------------------
217
+
218
+ /**
219
+ * Launches [intent] for [call], rejecting with `PENDING_OPERATION` if
220
+ * another picker is on screen and with `NOT_SUPPORTED` if no activity can
221
+ * handle [intent].
222
+ *
223
+ * @param call the call to resolve once the picker returns.
224
+ * @param intent the `ACTION_PICK` intent to launch.
225
+ * @param callbackName name of the `@ActivityCallback` that receives the result.
226
+ */
227
+ private fun startPicker(call: PluginCall, intent: Intent, callbackName: String) {
178
228
  if (pickInProgress) {
179
229
  reject(call, ContactsError.PENDING_OPERATION)
180
230
  return
181
231
  }
182
232
  pickInProgress = true
183
- val intent = Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI)
184
233
  try {
185
- startActivityForResult(call, intent, "pickContactResult")
234
+ startActivityForResult(call, intent, callbackName)
186
235
  } catch (e: Exception) {
187
236
  // No contacts app / picker activity on this device.
188
237
  pickInProgress = false
@@ -190,22 +239,35 @@ class ContactsPlugin : Plugin() {
190
239
  }
191
240
  }
192
241
 
193
- @ActivityCallback
194
- private fun pickContactResult(call: PluginCall?, result: androidx.activity.result.ActivityResult) {
242
+ /**
243
+ * Resolves [call] with what [read] returns for the picked URI, or rejects
244
+ * on cancel or failure. [read] runs on the executor, so it may query the
245
+ * provider.
246
+ *
247
+ * @param call the call that started the picker, null if it was lost.
248
+ * @param result the picker's activity result.
249
+ * @param read turns the picked URI into the result, null if it holds no data.
250
+ */
251
+ private fun handlePickResult(
252
+ call: PluginCall?,
253
+ result: androidx.activity.result.ActivityResult,
254
+ read: (Uri) -> JSObject?
255
+ ) {
195
256
  pickInProgress = false
196
257
  if (call == null) return
197
258
  when (result.resultCode) {
198
259
  Activity.RESULT_OK -> {
199
260
  val uri = result.data?.data
200
- val contactId = uri?.lastPathSegment
201
- if (contactId == null) {
261
+ if (uri == null) {
202
262
  reject(call, ContactsError.UNKNOWN)
203
263
  return
204
264
  }
205
265
  executor.execute {
206
266
  try {
207
- val contact = implementation.getContactById(contactId)
267
+ val contact = read(uri)
208
268
  if (contact != null) call.resolve(contact) else reject(call, ContactsError.UNKNOWN)
269
+ } catch (e: SecurityException) {
270
+ reject(call, ContactsError.PERMISSION_DENIED, e)
209
271
  } catch (e: Exception) {
210
272
  reject(call, ContactsError.UNKNOWN, e)
211
273
  }
@@ -226,8 +288,15 @@ class ContactsPlugin : Plugin() {
226
288
  else -> READ
227
289
  }
228
290
 
229
- /** Ensures the method's permission alias, then dispatches the saved call. */
291
+ /**
292
+ * Rejects with `PERMISSION_NOT_DECLARED` if the manifest lacks the method's permissions,
293
+ * otherwise ensures its permission alias and dispatches the saved call.
294
+ */
230
295
  private fun ensurePermission(call: PluginCall) {
296
+ if (!isPermissionDeclared(aliasFor(call))) {
297
+ reject(call, ContactsError.PERMISSION_NOT_DECLARED)
298
+ return
299
+ }
231
300
  if (getPermissionState(aliasFor(call)) == PermissionState.GRANTED) {
232
301
  dispatch(call)
233
302
  } else {
package/dist/docs.json CHANGED
@@ -92,6 +92,30 @@
92
92
  "Contact"
93
93
  ],
94
94
  "slug": "pickcontact"
95
+ },
96
+ {
97
+ "name": "pickContactField",
98
+ "signature": "(options: PickContactFieldOptions) => Promise<PickedContactField>",
99
+ "parameters": [
100
+ {
101
+ "name": "options",
102
+ "docs": "",
103
+ "type": "PickContactFieldOptions"
104
+ }
105
+ ],
106
+ "returns": "Promise<PickedContactField>",
107
+ "tags": [
108
+ {
109
+ "name": "since",
110
+ "text": "1.1.0"
111
+ }
112
+ ],
113
+ "docs": "Launches the native contact picker UI, showing only the requested kind of\ninformation, and resolves with the single value the user selects (not a\nfull contact). Rejects with `OS-PLUG-CONT-0006` if the user cancels.\n\nNeeds no contacts permission on either platform, which lets Android apps\nomit READ_CONTACTS from their manifest. Only one data kind can be picked\nper call.",
114
+ "complexTypes": [
115
+ "PickedContactField",
116
+ "PickContactFieldOptions"
117
+ ],
118
+ "slug": "pickcontactfield"
95
119
  }
96
120
  ],
97
121
  "properties": []
@@ -824,6 +848,182 @@
824
848
  "type": "string"
825
849
  }
826
850
  ]
851
+ },
852
+ {
853
+ "name": "PickedContactField",
854
+ "slug": "pickedcontactfield",
855
+ "docs": "The value the user picked with {@link ContactsPlugin.pickContactField}. This is\nnot a full contact: it holds only the picked value, its label and the\ncontact's display name.",
856
+ "tags": [
857
+ {
858
+ "text": "1.1.0",
859
+ "name": "since"
860
+ }
861
+ ],
862
+ "methods": [],
863
+ "properties": [
864
+ {
865
+ "name": "field",
866
+ "tags": [
867
+ {
868
+ "text": "1.1.0",
869
+ "name": "since"
870
+ }
871
+ ],
872
+ "docs": "The kind of value that was picked, as requested.",
873
+ "complexTypes": [],
874
+ "type": "'phone' | 'email' | 'address'"
875
+ },
876
+ {
877
+ "name": "value",
878
+ "tags": [
879
+ {
880
+ "text": "1.1.0",
881
+ "name": "since"
882
+ }
883
+ ],
884
+ "docs": "The picked phone number, email address, or postal address formatted for\ndisplay, depending on `field`.",
885
+ "complexTypes": [],
886
+ "type": "string"
887
+ },
888
+ {
889
+ "name": "type",
890
+ "tags": [
891
+ {
892
+ "text": "1.1.0",
893
+ "name": "since"
894
+ }
895
+ ],
896
+ "docs": "The label of the picked value, e.g. `mobile`, `home`, `work`.",
897
+ "complexTypes": [],
898
+ "type": "string"
899
+ },
900
+ {
901
+ "name": "displayName",
902
+ "tags": [
903
+ {
904
+ "text": "1.1.0",
905
+ "name": "since"
906
+ }
907
+ ],
908
+ "docs": "The display name of the contact the value belongs to, when available.",
909
+ "complexTypes": [],
910
+ "type": "string | undefined"
911
+ },
912
+ {
913
+ "name": "address",
914
+ "tags": [
915
+ {
916
+ "text": "1.1.0",
917
+ "name": "since"
918
+ }
919
+ ],
920
+ "docs": "The parts of the postal address. Only present when `field` is `address`.",
921
+ "complexTypes": [
922
+ "PickedContactAddress"
923
+ ],
924
+ "type": "PickedContactAddress"
925
+ }
926
+ ]
927
+ },
928
+ {
929
+ "name": "PickedContactAddress",
930
+ "slug": "pickedcontactaddress",
931
+ "docs": "The parts of a postal address returned by {@link ContactsPlugin.pickContactField}.",
932
+ "tags": [
933
+ {
934
+ "text": "1.1.0",
935
+ "name": "since"
936
+ }
937
+ ],
938
+ "methods": [],
939
+ "properties": [
940
+ {
941
+ "name": "streetAddress",
942
+ "tags": [
943
+ {
944
+ "text": "1.1.0",
945
+ "name": "since"
946
+ }
947
+ ],
948
+ "docs": "The street address.",
949
+ "complexTypes": [],
950
+ "type": "string | undefined"
951
+ },
952
+ {
953
+ "name": "locality",
954
+ "tags": [
955
+ {
956
+ "text": "1.1.0",
957
+ "name": "since"
958
+ }
959
+ ],
960
+ "docs": "The city or locality.",
961
+ "complexTypes": [],
962
+ "type": "string | undefined"
963
+ },
964
+ {
965
+ "name": "region",
966
+ "tags": [
967
+ {
968
+ "text": "1.1.0",
969
+ "name": "since"
970
+ }
971
+ ],
972
+ "docs": "The state or region.",
973
+ "complexTypes": [],
974
+ "type": "string | undefined"
975
+ },
976
+ {
977
+ "name": "postalCode",
978
+ "tags": [
979
+ {
980
+ "text": "1.1.0",
981
+ "name": "since"
982
+ }
983
+ ],
984
+ "docs": "The postal code.",
985
+ "complexTypes": [],
986
+ "type": "string | undefined"
987
+ },
988
+ {
989
+ "name": "country",
990
+ "tags": [
991
+ {
992
+ "text": "1.1.0",
993
+ "name": "since"
994
+ }
995
+ ],
996
+ "docs": "The country.",
997
+ "complexTypes": [],
998
+ "type": "string | undefined"
999
+ }
1000
+ ]
1001
+ },
1002
+ {
1003
+ "name": "PickContactFieldOptions",
1004
+ "slug": "pickcontactfieldoptions",
1005
+ "docs": "Options accepted by {@link ContactsPlugin.pickContactField}.",
1006
+ "tags": [
1007
+ {
1008
+ "text": "1.1.0",
1009
+ "name": "since"
1010
+ }
1011
+ ],
1012
+ "methods": [],
1013
+ "properties": [
1014
+ {
1015
+ "name": "field",
1016
+ "tags": [
1017
+ {
1018
+ "text": "1.1.0",
1019
+ "name": "since"
1020
+ }
1021
+ ],
1022
+ "docs": "The single kind of contact information to pick. Any other value\nrejects with `OS-PLUG-CONT-0001`.",
1023
+ "complexTypes": [],
1024
+ "type": "'phone' | 'email' | 'address'"
1025
+ }
1026
+ ]
827
1027
  }
828
1028
  ],
829
1029
  "enums": [],
@@ -49,6 +49,18 @@ export interface ContactsPlugin {
49
49
  * @since 1.0.0
50
50
  */
51
51
  pickContact(): Promise<Contact>;
52
+ /**
53
+ * Launches the native contact picker UI, showing only the requested kind of
54
+ * information, and resolves with the single value the user selects (not a
55
+ * full contact). Rejects with `OS-PLUG-CONT-0006` if the user cancels.
56
+ *
57
+ * Needs no contacts permission on either platform, which lets Android apps
58
+ * omit READ_CONTACTS from their manifest. Only one data kind can be picked
59
+ * per call.
60
+ *
61
+ * @since 1.1.0
62
+ */
63
+ pickContactField(options: PickContactFieldOptions): Promise<PickedContactField>;
52
64
  }
53
65
  /**
54
66
  * The set of contact fields a {@link ContactsPlugin.find} call can search
@@ -438,3 +450,94 @@ export interface ContactOrganization {
438
450
  */
439
451
  title?: string;
440
452
  }
453
+ /**
454
+ * Options accepted by {@link ContactsPlugin.pickContactField}.
455
+ *
456
+ * @since 1.1.0
457
+ */
458
+ export interface PickContactFieldOptions {
459
+ /**
460
+ * The single kind of contact information to pick. Any other value
461
+ * rejects with `OS-PLUG-CONT-0001`.
462
+ *
463
+ * @since 1.1.0
464
+ */
465
+ field: 'phone' | 'email' | 'address';
466
+ }
467
+ /**
468
+ * The value the user picked with {@link ContactsPlugin.pickContactField}. This is
469
+ * not a full contact: it holds only the picked value, its label and the
470
+ * contact's display name.
471
+ *
472
+ * @since 1.1.0
473
+ */
474
+ export interface PickedContactField {
475
+ /**
476
+ * The kind of value that was picked, as requested.
477
+ *
478
+ * @since 1.1.0
479
+ */
480
+ field: 'phone' | 'email' | 'address';
481
+ /**
482
+ * The picked phone number, email address, or postal address formatted for
483
+ * display, depending on `field`.
484
+ *
485
+ * @since 1.1.0
486
+ */
487
+ value: string;
488
+ /**
489
+ * The label of the picked value, e.g. `mobile`, `home`, `work`.
490
+ *
491
+ * @since 1.1.0
492
+ */
493
+ type: string;
494
+ /**
495
+ * The display name of the contact the value belongs to, when available.
496
+ *
497
+ * @since 1.1.0
498
+ */
499
+ displayName?: string;
500
+ /**
501
+ * The parts of the postal address. Only present when `field` is `address`.
502
+ *
503
+ * @since 1.1.0
504
+ */
505
+ address?: PickedContactAddress;
506
+ }
507
+ /**
508
+ * The parts of a postal address returned by {@link ContactsPlugin.pickContactField}.
509
+ *
510
+ * @since 1.1.0
511
+ */
512
+ export interface PickedContactAddress {
513
+ /**
514
+ * The street address.
515
+ *
516
+ * @since 1.1.0
517
+ */
518
+ streetAddress?: string;
519
+ /**
520
+ * The city or locality.
521
+ *
522
+ * @since 1.1.0
523
+ */
524
+ locality?: string;
525
+ /**
526
+ * The state or region.
527
+ *
528
+ * @since 1.1.0
529
+ */
530
+ region?: string;
531
+ /**
532
+ * The postal code.
533
+ *
534
+ * @since 1.1.0
535
+ */
536
+ postalCode?: string;
537
+ /**
538
+ * The country.
539
+ *
540
+ * @since 1.1.0
541
+ */
542
+ country?: string;
543
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface ContactsPlugin {\n /**\n * Queries the device contacts database and returns the matching contacts.\n *\n * Requests the READ_CONTACTS (Android) / Contacts (iOS) permission internally\n * the first time it runs; there is no separate permission method.\n *\n * **iOS 18+:** under Limited Access the search runs against (and returns\n * only) the subset of contacts the user shared with the app.\n *\n * @since 1.0.0\n */\n find(options: ContactFindOptions): Promise<ContactFindResult>;\n\n /**\n * Persists a new contact or updates an existing one (matched by `contact.id`).\n * Resolves with the full saved contact.\n *\n * Requests the READ/WRITE_CONTACTS (Android) / Contacts (iOS) permission\n * internally.\n *\n * **iOS 18+:** works under Limited Access: new contacts are added to the\n * app's accessible set; updating requires the target contact to be in that\n * set (otherwise the call rejects with `OS-PLUG-CONT-0001`).\n *\n * @since 1.0.0\n */\n save(options: ContactSaveOptions): Promise<Contact>;\n\n /**\n * Removes the contact with the given `id` from the device contacts database.\n * Rejects with `OS-PLUG-CONT-0001` when no contact has that id (on iOS 18+\n * Limited Access, also when the contact is outside the accessible set).\n *\n * Requests the READ/WRITE_CONTACTS (Android) / Contacts (iOS) permission\n * internally.\n *\n * @since 1.0.0\n */\n remove(options: ContactRemoveOptions): Promise<void>;\n\n /**\n * Launches the native contact picker UI and resolves with the contact the\n * user selects. Rejects with `OS-PLUG-CONT-0006` if the user cancels.\n *\n * On iOS the system picker requires no permission and always shows the full\n * contact list, even under iOS 18+ Limited Access (the picked contact is\n * returned without joining the app's accessible set). On Android the\n * READ_CONTACTS permission is requested internally to read the picked\n * contact's details.\n *\n * @since 1.0.0\n */\n pickContact(): Promise<Contact>;\n}\n\n/**\n * The set of contact fields a {@link ContactsPlugin.find} call can search\n * against or request back. Mirrors the legacy Cordova `ContactFieldType`\n * string values exactly.\n *\n * @since 1.0.0\n */\nexport type ContactFieldType =\n | 'addresses'\n | 'birthday'\n | 'categories'\n | 'country'\n | 'department'\n | 'displayName'\n | 'emails'\n | 'familyName'\n | 'formatted'\n | 'givenName'\n | 'honorificPrefix'\n | 'honorificSuffix'\n | 'id'\n | 'ims'\n | 'locality'\n | 'middleName'\n | 'name'\n | 'nickname'\n | 'note'\n | 'organizations'\n | 'phoneNumbers'\n | 'photos'\n | 'postalCode'\n | 'region'\n | 'streetAddress'\n | 'title'\n | 'urls';\n\n/**\n * Search options accepted by {@link ContactsPlugin.find}.\n *\n * @since 1.0.0\n */\nexport interface ContactFindOptions {\n /**\n * Fields to search against. Pass `['*']` to match every field. An empty\n * array is invalid and rejects with `OS-PLUG-CONT-0001`. The `id` field\n * matches by exact identifier; all other fields match case-insensitive\n * substrings. `photos` and `categories` are not searchable.\n *\n * @since 1.0.0\n */\n fields: ContactFieldType[];\n\n /**\n * Search string matched (case-insensitively) against the selected `fields`.\n * An empty/omitted filter returns every contact.\n *\n * @since 1.0.0\n */\n filter?: string;\n\n /**\n * When `true`, returns every match; when `false` (default), returns at most\n * one contact.\n *\n * @since 1.0.0\n */\n multiple?: boolean;\n\n /**\n * If set, each returned {@link Contact} only includes these fields (plus the\n * always-present `id`).\n *\n * @since 1.0.0\n */\n desiredFields?: ContactFieldType[];\n\n /**\n * OutSystems extension: when `true`, only contacts that have at least one\n * phone number are returned. Defaults to `false`.\n *\n * @since 1.0.0\n */\n hasPhoneNumber?: boolean;\n}\n\n/**\n * Result of a {@link ContactsPlugin.find} call.\n *\n * @since 1.0.0\n */\nexport interface ContactFindResult {\n /**\n * The contacts matching the search criteria.\n *\n * @since 1.0.0\n */\n contacts: Contact[];\n}\n\n/**\n * Options accepted by {@link ContactsPlugin.save}.\n *\n * @since 1.0.0\n */\nexport interface ContactSaveOptions {\n /**\n * The contact to create (no `id`) or update (existing `id`).\n *\n * Update semantics: every field present on the contact replaces the stored\n * value entirely (e.g. `name` replaces the whole structured name,\n * `phoneNumbers` replaces all phone numbers); omitted fields are left\n * unchanged.\n *\n * @since 1.0.0\n */\n contact: Contact;\n}\n\n/**\n * Options accepted by {@link ContactsPlugin.remove}.\n *\n * @since 1.0.0\n */\nexport interface ContactRemoveOptions {\n /**\n * The native id of the contact to remove.\n *\n * @since 1.0.0\n */\n id: string;\n}\n\n/**\n * A single device contact.\n *\n * @since 1.0.0\n */\nexport interface Contact {\n /**\n * Globally unique, platform-assigned identifier. Absent for contacts not yet\n * saved to the device.\n *\n * @since 1.0.0\n */\n id?: string;\n\n /**\n * Android raw-contact id backing this aggregated contact. iOS leaves this\n * unset.\n *\n * @since 1.0.0\n */\n rawId?: string;\n\n /**\n * Name suitable for display to end users.\n *\n * @since 1.0.0\n */\n displayName?: string;\n\n /**\n * The structured name components.\n *\n * @since 1.0.0\n */\n name?: ContactName;\n\n /**\n * A casual name by which to address the contact.\n *\n * @since 1.0.0\n */\n nickname?: string;\n\n /**\n * The contact's phone numbers.\n *\n * @since 1.0.0\n */\n phoneNumbers?: ContactField[];\n\n /**\n * The contact's email addresses.\n *\n * @since 1.0.0\n */\n emails?: ContactField[];\n\n /**\n * The contact's postal addresses.\n *\n * @since 1.0.0\n */\n addresses?: ContactAddress[];\n\n /**\n * The contact's instant-messaging handles.\n *\n * @since 1.0.0\n */\n ims?: ContactField[];\n\n /**\n * The contact's organizations.\n *\n * @since 1.0.0\n */\n organizations?: ContactOrganization[];\n\n /**\n * The contact's birthday as epoch milliseconds.\n *\n * @since 1.0.0\n */\n birthday?: number;\n\n /**\n * A free-form note about the contact.\n *\n * **iOS:** not supported by default: reading/writing a contact's note\n * requires Apple's restricted `com.apple.developer.contacts.notes`\n * entitlement. Without it the field is omitted on read and ignored on save.\n * Android has no such restriction.\n *\n * @since 1.0.0\n */\n note?: string;\n\n /**\n * The contact's photos. Reads return `type: 'url'` with the `value`\n * holding a reference to the image, never image bytes: on Android the\n * contact's `content://` photo URI, on iOS the path of a copy written to\n * the app's temporary directory (cleared by the system). On save, the first entry is\n * applied: pass `type: 'base64'` with base64 data, or `type: 'url'` with a\n * local `file://`/`content://` URI to import.\n *\n * @since 1.0.0\n */\n photos?: ContactField[];\n\n /**\n * User-defined categories associated with the contact. Read-only: populated\n * from the contact's group memberships on Android, never returned on iOS\n * (the Contacts framework has no equivalent), and ignored on save.\n *\n * @since 1.0.0\n */\n categories?: ContactField[];\n\n /**\n * Web pages associated with the contact.\n *\n * @since 1.0.0\n */\n urls?: ContactField[];\n}\n\n/**\n * Structured name of a {@link Contact}.\n *\n * @since 1.0.0\n */\nexport interface ContactName {\n /**\n * The complete formatted name.\n *\n * @since 1.0.0\n */\n formatted?: string;\n\n /**\n * Family (last) name.\n *\n * @since 1.0.0\n */\n familyName?: string;\n\n /**\n * Given (first) name.\n *\n * @since 1.0.0\n */\n givenName?: string;\n\n /**\n * Middle name.\n *\n * @since 1.0.0\n */\n middleName?: string;\n\n /**\n * Honorific prefix (e.g. `Mr.`, `Dr.`).\n *\n * @since 1.0.0\n */\n honorificPrefix?: string;\n\n /**\n * Honorific suffix (e.g. `Esq.`).\n *\n * @since 1.0.0\n */\n honorificSuffix?: string;\n}\n\n/**\n * A generic, repeatable contact field (phone number, email, IM, photo, URL,\n * category).\n *\n * @since 1.0.0\n */\nexport interface ContactField {\n /**\n * The kind of field, e.g. `home`, `work`, `mobile`. For photos, `url` or\n * `base64`.\n *\n * @since 1.0.0\n */\n type?: string;\n\n /**\n * The field value (phone number, email address, URI, etc.).\n *\n * @since 1.0.0\n */\n value?: string;\n\n /**\n * `true` if this is the contact's preferred value for the field.\n *\n * @since 1.0.0\n */\n pref?: boolean;\n\n /**\n * Platform-assigned id of this individual field entry.\n *\n * @since 1.0.0\n */\n id?: string;\n}\n\n/**\n * A postal address of a {@link Contact}.\n *\n * @since 1.0.0\n */\nexport interface ContactAddress {\n /**\n * Platform-assigned id of this address entry.\n *\n * @since 1.0.0\n */\n id?: string;\n\n /**\n * `true` if this is the contact's preferred address.\n *\n * @since 1.0.0\n */\n pref?: boolean;\n\n /**\n * The kind of address, e.g. `home`, `work`.\n *\n * @since 1.0.0\n */\n type?: string;\n\n /**\n * The full address formatted for display.\n *\n * @since 1.0.0\n */\n formatted?: string;\n\n /**\n * The street address.\n *\n * @since 1.0.0\n */\n streetAddress?: string;\n\n /**\n * The city or locality.\n *\n * @since 1.0.0\n */\n locality?: string;\n\n /**\n * The state or region.\n *\n * @since 1.0.0\n */\n region?: string;\n\n /**\n * The ZIP or postal code.\n *\n * @since 1.0.0\n */\n postalCode?: string;\n\n /**\n * The country name.\n *\n * @since 1.0.0\n */\n country?: string;\n}\n\n/**\n * An organization a {@link Contact} belongs to.\n *\n * @since 1.0.0\n */\nexport interface ContactOrganization {\n /**\n * Platform-assigned id of this organization entry. Android only; iOS\n * models the organization as flat contact properties without an id.\n *\n * @since 1.0.0\n */\n id?: string;\n\n /**\n * `true` if this is the contact's preferred organization.\n *\n * @since 1.0.0\n */\n pref?: boolean;\n\n /**\n * The kind of organization, e.g. `work`.\n *\n * @since 1.0.0\n */\n type?: string;\n\n /**\n * The organization name.\n *\n * @since 1.0.0\n */\n name?: string;\n\n /**\n * The department within the organization.\n *\n * @since 1.0.0\n */\n department?: string;\n\n /**\n * The contact's title at the organization.\n *\n * @since 1.0.0\n */\n title?: string;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface ContactsPlugin {\n /**\n * Queries the device contacts database and returns the matching contacts.\n *\n * Requests the READ_CONTACTS (Android) / Contacts (iOS) permission internally\n * the first time it runs; there is no separate permission method.\n *\n * **iOS 18+:** under Limited Access the search runs against (and returns\n * only) the subset of contacts the user shared with the app.\n *\n * @since 1.0.0\n */\n find(options: ContactFindOptions): Promise<ContactFindResult>;\n\n /**\n * Persists a new contact or updates an existing one (matched by `contact.id`).\n * Resolves with the full saved contact.\n *\n * Requests the READ/WRITE_CONTACTS (Android) / Contacts (iOS) permission\n * internally.\n *\n * **iOS 18+:** works under Limited Access: new contacts are added to the\n * app's accessible set; updating requires the target contact to be in that\n * set (otherwise the call rejects with `OS-PLUG-CONT-0001`).\n *\n * @since 1.0.0\n */\n save(options: ContactSaveOptions): Promise<Contact>;\n\n /**\n * Removes the contact with the given `id` from the device contacts database.\n * Rejects with `OS-PLUG-CONT-0001` when no contact has that id (on iOS 18+\n * Limited Access, also when the contact is outside the accessible set).\n *\n * Requests the READ/WRITE_CONTACTS (Android) / Contacts (iOS) permission\n * internally.\n *\n * @since 1.0.0\n */\n remove(options: ContactRemoveOptions): Promise<void>;\n\n /**\n * Launches the native contact picker UI and resolves with the contact the\n * user selects. Rejects with `OS-PLUG-CONT-0006` if the user cancels.\n *\n * On iOS the system picker requires no permission and always shows the full\n * contact list, even under iOS 18+ Limited Access (the picked contact is\n * returned without joining the app's accessible set). On Android the\n * READ_CONTACTS permission is requested internally to read the picked\n * contact's details.\n *\n * @since 1.0.0\n */\n pickContact(): Promise<Contact>;\n\n /**\n * Launches the native contact picker UI, showing only the requested kind of\n * information, and resolves with the single value the user selects (not a\n * full contact). Rejects with `OS-PLUG-CONT-0006` if the user cancels.\n *\n * Needs no contacts permission on either platform, which lets Android apps\n * omit READ_CONTACTS from their manifest. Only one data kind can be picked\n * per call.\n *\n * @since 1.1.0\n */\n pickContactField(options: PickContactFieldOptions): Promise<PickedContactField>;\n}\n\n/**\n * The set of contact fields a {@link ContactsPlugin.find} call can search\n * against or request back. Mirrors the legacy Cordova `ContactFieldType`\n * string values exactly.\n *\n * @since 1.0.0\n */\nexport type ContactFieldType =\n | 'addresses'\n | 'birthday'\n | 'categories'\n | 'country'\n | 'department'\n | 'displayName'\n | 'emails'\n | 'familyName'\n | 'formatted'\n | 'givenName'\n | 'honorificPrefix'\n | 'honorificSuffix'\n | 'id'\n | 'ims'\n | 'locality'\n | 'middleName'\n | 'name'\n | 'nickname'\n | 'note'\n | 'organizations'\n | 'phoneNumbers'\n | 'photos'\n | 'postalCode'\n | 'region'\n | 'streetAddress'\n | 'title'\n | 'urls';\n\n/**\n * Search options accepted by {@link ContactsPlugin.find}.\n *\n * @since 1.0.0\n */\nexport interface ContactFindOptions {\n /**\n * Fields to search against. Pass `['*']` to match every field. An empty\n * array is invalid and rejects with `OS-PLUG-CONT-0001`. The `id` field\n * matches by exact identifier; all other fields match case-insensitive\n * substrings. `photos` and `categories` are not searchable.\n *\n * @since 1.0.0\n */\n fields: ContactFieldType[];\n\n /**\n * Search string matched (case-insensitively) against the selected `fields`.\n * An empty/omitted filter returns every contact.\n *\n * @since 1.0.0\n */\n filter?: string;\n\n /**\n * When `true`, returns every match; when `false` (default), returns at most\n * one contact.\n *\n * @since 1.0.0\n */\n multiple?: boolean;\n\n /**\n * If set, each returned {@link Contact} only includes these fields (plus the\n * always-present `id`).\n *\n * @since 1.0.0\n */\n desiredFields?: ContactFieldType[];\n\n /**\n * OutSystems extension: when `true`, only contacts that have at least one\n * phone number are returned. Defaults to `false`.\n *\n * @since 1.0.0\n */\n hasPhoneNumber?: boolean;\n}\n\n/**\n * Result of a {@link ContactsPlugin.find} call.\n *\n * @since 1.0.0\n */\nexport interface ContactFindResult {\n /**\n * The contacts matching the search criteria.\n *\n * @since 1.0.0\n */\n contacts: Contact[];\n}\n\n/**\n * Options accepted by {@link ContactsPlugin.save}.\n *\n * @since 1.0.0\n */\nexport interface ContactSaveOptions {\n /**\n * The contact to create (no `id`) or update (existing `id`).\n *\n * Update semantics: every field present on the contact replaces the stored\n * value entirely (e.g. `name` replaces the whole structured name,\n * `phoneNumbers` replaces all phone numbers); omitted fields are left\n * unchanged.\n *\n * @since 1.0.0\n */\n contact: Contact;\n}\n\n/**\n * Options accepted by {@link ContactsPlugin.remove}.\n *\n * @since 1.0.0\n */\nexport interface ContactRemoveOptions {\n /**\n * The native id of the contact to remove.\n *\n * @since 1.0.0\n */\n id: string;\n}\n\n/**\n * A single device contact.\n *\n * @since 1.0.0\n */\nexport interface Contact {\n /**\n * Globally unique, platform-assigned identifier. Absent for contacts not yet\n * saved to the device.\n *\n * @since 1.0.0\n */\n id?: string;\n\n /**\n * Android raw-contact id backing this aggregated contact. iOS leaves this\n * unset.\n *\n * @since 1.0.0\n */\n rawId?: string;\n\n /**\n * Name suitable for display to end users.\n *\n * @since 1.0.0\n */\n displayName?: string;\n\n /**\n * The structured name components.\n *\n * @since 1.0.0\n */\n name?: ContactName;\n\n /**\n * A casual name by which to address the contact.\n *\n * @since 1.0.0\n */\n nickname?: string;\n\n /**\n * The contact's phone numbers.\n *\n * @since 1.0.0\n */\n phoneNumbers?: ContactField[];\n\n /**\n * The contact's email addresses.\n *\n * @since 1.0.0\n */\n emails?: ContactField[];\n\n /**\n * The contact's postal addresses.\n *\n * @since 1.0.0\n */\n addresses?: ContactAddress[];\n\n /**\n * The contact's instant-messaging handles.\n *\n * @since 1.0.0\n */\n ims?: ContactField[];\n\n /**\n * The contact's organizations.\n *\n * @since 1.0.0\n */\n organizations?: ContactOrganization[];\n\n /**\n * The contact's birthday as epoch milliseconds.\n *\n * @since 1.0.0\n */\n birthday?: number;\n\n /**\n * A free-form note about the contact.\n *\n * **iOS:** not supported by default: reading/writing a contact's note\n * requires Apple's restricted `com.apple.developer.contacts.notes`\n * entitlement. Without it the field is omitted on read and ignored on save.\n * Android has no such restriction.\n *\n * @since 1.0.0\n */\n note?: string;\n\n /**\n * The contact's photos. Reads return `type: 'url'` with the `value`\n * holding a reference to the image, never image bytes: on Android the\n * contact's `content://` photo URI, on iOS the path of a copy written to\n * the app's temporary directory (cleared by the system). On save, the first entry is\n * applied: pass `type: 'base64'` with base64 data, or `type: 'url'` with a\n * local `file://`/`content://` URI to import.\n *\n * @since 1.0.0\n */\n photos?: ContactField[];\n\n /**\n * User-defined categories associated with the contact. Read-only: populated\n * from the contact's group memberships on Android, never returned on iOS\n * (the Contacts framework has no equivalent), and ignored on save.\n *\n * @since 1.0.0\n */\n categories?: ContactField[];\n\n /**\n * Web pages associated with the contact.\n *\n * @since 1.0.0\n */\n urls?: ContactField[];\n}\n\n/**\n * Structured name of a {@link Contact}.\n *\n * @since 1.0.0\n */\nexport interface ContactName {\n /**\n * The complete formatted name.\n *\n * @since 1.0.0\n */\n formatted?: string;\n\n /**\n * Family (last) name.\n *\n * @since 1.0.0\n */\n familyName?: string;\n\n /**\n * Given (first) name.\n *\n * @since 1.0.0\n */\n givenName?: string;\n\n /**\n * Middle name.\n *\n * @since 1.0.0\n */\n middleName?: string;\n\n /**\n * Honorific prefix (e.g. `Mr.`, `Dr.`).\n *\n * @since 1.0.0\n */\n honorificPrefix?: string;\n\n /**\n * Honorific suffix (e.g. `Esq.`).\n *\n * @since 1.0.0\n */\n honorificSuffix?: string;\n}\n\n/**\n * A generic, repeatable contact field (phone number, email, IM, photo, URL,\n * category).\n *\n * @since 1.0.0\n */\nexport interface ContactField {\n /**\n * The kind of field, e.g. `home`, `work`, `mobile`. For photos, `url` or\n * `base64`.\n *\n * @since 1.0.0\n */\n type?: string;\n\n /**\n * The field value (phone number, email address, URI, etc.).\n *\n * @since 1.0.0\n */\n value?: string;\n\n /**\n * `true` if this is the contact's preferred value for the field.\n *\n * @since 1.0.0\n */\n pref?: boolean;\n\n /**\n * Platform-assigned id of this individual field entry.\n *\n * @since 1.0.0\n */\n id?: string;\n}\n\n/**\n * A postal address of a {@link Contact}.\n *\n * @since 1.0.0\n */\nexport interface ContactAddress {\n /**\n * Platform-assigned id of this address entry.\n *\n * @since 1.0.0\n */\n id?: string;\n\n /**\n * `true` if this is the contact's preferred address.\n *\n * @since 1.0.0\n */\n pref?: boolean;\n\n /**\n * The kind of address, e.g. `home`, `work`.\n *\n * @since 1.0.0\n */\n type?: string;\n\n /**\n * The full address formatted for display.\n *\n * @since 1.0.0\n */\n formatted?: string;\n\n /**\n * The street address.\n *\n * @since 1.0.0\n */\n streetAddress?: string;\n\n /**\n * The city or locality.\n *\n * @since 1.0.0\n */\n locality?: string;\n\n /**\n * The state or region.\n *\n * @since 1.0.0\n */\n region?: string;\n\n /**\n * The ZIP or postal code.\n *\n * @since 1.0.0\n */\n postalCode?: string;\n\n /**\n * The country name.\n *\n * @since 1.0.0\n */\n country?: string;\n}\n\n/**\n * An organization a {@link Contact} belongs to.\n *\n * @since 1.0.0\n */\nexport interface ContactOrganization {\n /**\n * Platform-assigned id of this organization entry. Android only; iOS\n * models the organization as flat contact properties without an id.\n *\n * @since 1.0.0\n */\n id?: string;\n\n /**\n * `true` if this is the contact's preferred organization.\n *\n * @since 1.0.0\n */\n pref?: boolean;\n\n /**\n * The kind of organization, e.g. `work`.\n *\n * @since 1.0.0\n */\n type?: string;\n\n /**\n * The organization name.\n *\n * @since 1.0.0\n */\n name?: string;\n\n /**\n * The department within the organization.\n *\n * @since 1.0.0\n */\n department?: string;\n\n /**\n * The contact's title at the organization.\n *\n * @since 1.0.0\n */\n title?: string;\n}\n\n/**\n * Options accepted by {@link ContactsPlugin.pickContactField}.\n *\n * @since 1.1.0\n */\nexport interface PickContactFieldOptions {\n /**\n * The single kind of contact information to pick. Any other value\n * rejects with `OS-PLUG-CONT-0001`.\n *\n * @since 1.1.0\n */\n field: 'phone' | 'email' | 'address';\n}\n\n/**\n * The value the user picked with {@link ContactsPlugin.pickContactField}. This is\n * not a full contact: it holds only the picked value, its label and the\n * contact's display name.\n *\n * @since 1.1.0\n */\nexport interface PickedContactField {\n /**\n * The kind of value that was picked, as requested.\n *\n * @since 1.1.0\n */\n field: 'phone' | 'email' | 'address';\n\n /**\n * The picked phone number, email address, or postal address formatted for\n * display, depending on `field`.\n *\n * @since 1.1.0\n */\n value: string;\n\n /**\n * The label of the picked value, e.g. `mobile`, `home`, `work`.\n *\n * @since 1.1.0\n */\n type: string;\n\n /**\n * The display name of the contact the value belongs to, when available.\n *\n * @since 1.1.0\n */\n displayName?: string;\n\n /**\n * The parts of the postal address. Only present when `field` is `address`.\n *\n * @since 1.1.0\n */\n address?: PickedContactAddress;\n}\n\n/**\n * The parts of a postal address returned by {@link ContactsPlugin.pickContactField}.\n *\n * @since 1.1.0\n */\nexport interface PickedContactAddress {\n /**\n * The street address.\n *\n * @since 1.1.0\n */\n streetAddress?: string;\n\n /**\n * The city or locality.\n *\n * @since 1.1.0\n */\n locality?: string;\n\n /**\n * The state or region.\n *\n * @since 1.1.0\n */\n region?: string;\n\n /**\n * The postal code.\n *\n * @since 1.1.0\n */\n postalCode?: string;\n\n /**\n * The country.\n *\n * @since 1.1.0\n */\n country?: string;\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
- import type { Contact, ContactFindOptions, ContactFindResult, ContactRemoveOptions, ContactSaveOptions, ContactsPlugin } from './definitions';
2
+ import type { Contact, ContactFindOptions, ContactFindResult, ContactRemoveOptions, ContactSaveOptions, ContactsPlugin, PickContactFieldOptions, PickedContactField } from './definitions';
3
3
  /**
4
4
  * Web implementation. The browser has no standardized, broadly-available
5
5
  * contacts database API (the Contact Picker API is limited, gated, and
@@ -11,4 +11,5 @@ export declare class ContactsWeb extends WebPlugin implements ContactsPlugin {
11
11
  save(_options: ContactSaveOptions): Promise<Contact>;
12
12
  remove(_options: ContactRemoveOptions): Promise<void>;
13
13
  pickContact(): Promise<Contact>;
14
+ pickContactField(_options: PickContactFieldOptions): Promise<PickedContactField>;
14
15
  }
package/dist/esm/web.js CHANGED
@@ -18,5 +18,8 @@ export class ContactsWeb extends WebPlugin {
18
18
  async pickContact() {
19
19
  throw this.unimplemented('Contacts.pickContact() is not available on web.');
20
20
  }
21
+ async pickContactField(_options) {
22
+ throw this.unimplemented('Contacts.pickContactField() is not available on web.');
23
+ }
21
24
  }
22
25
  //# sourceMappingURL=web.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C;;;;;GAKG;AACH,MAAM,OAAO,WAAY,SAAQ,SAAS;IACxC,KAAK,CAAC,IAAI,CAAC,QAA4B;QACrC,MAAM,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAA4B;QACrC,MAAM,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,QAA8B;QACzC,MAAM,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC,CAAC;IACzE,CAAC;IAED,KAAK,CAAC,WAAW;QACf,MAAM,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC,CAAC;IAC9E,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n Contact,\n ContactFindOptions,\n ContactFindResult,\n ContactRemoveOptions,\n ContactSaveOptions,\n ContactsPlugin,\n} from './definitions';\n\n/**\n * Web implementation. The browser has no standardized, broadly-available\n * contacts database API (the Contact Picker API is limited, gated, and\n * read-only), so every method throws `unimplemented()`. The plugin is\n * native-only on iOS and Android.\n */\nexport class ContactsWeb extends WebPlugin implements ContactsPlugin {\n async find(_options: ContactFindOptions): Promise<ContactFindResult> {\n throw this.unimplemented('Contacts.find() is not available on web.');\n }\n\n async save(_options: ContactSaveOptions): Promise<Contact> {\n throw this.unimplemented('Contacts.save() is not available on web.');\n }\n\n async remove(_options: ContactRemoveOptions): Promise<void> {\n throw this.unimplemented('Contacts.remove() is not available on web.');\n }\n\n async pickContact(): Promise<Contact> {\n throw this.unimplemented('Contacts.pickContact() is not available on web.');\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAa5C;;;;;GAKG;AACH,MAAM,OAAO,WAAY,SAAQ,SAAS;IACxC,KAAK,CAAC,IAAI,CAAC,QAA4B;QACrC,MAAM,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAA4B;QACrC,MAAM,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,QAA8B;QACzC,MAAM,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC,CAAC;IACzE,CAAC;IAED,KAAK,CAAC,WAAW;QACf,MAAM,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,QAAiC;QACtD,MAAM,IAAI,CAAC,aAAa,CAAC,sDAAsD,CAAC,CAAC;IACnF,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n Contact,\n ContactFindOptions,\n ContactFindResult,\n ContactRemoveOptions,\n ContactSaveOptions,\n ContactsPlugin,\n PickContactFieldOptions,\n PickedContactField,\n} from './definitions';\n\n/**\n * Web implementation. The browser has no standardized, broadly-available\n * contacts database API (the Contact Picker API is limited, gated, and\n * read-only), so every method throws `unimplemented()`. The plugin is\n * native-only on iOS and Android.\n */\nexport class ContactsWeb extends WebPlugin implements ContactsPlugin {\n async find(_options: ContactFindOptions): Promise<ContactFindResult> {\n throw this.unimplemented('Contacts.find() is not available on web.');\n }\n\n async save(_options: ContactSaveOptions): Promise<Contact> {\n throw this.unimplemented('Contacts.save() is not available on web.');\n }\n\n async remove(_options: ContactRemoveOptions): Promise<void> {\n throw this.unimplemented('Contacts.remove() is not available on web.');\n }\n\n async pickContact(): Promise<Contact> {\n throw this.unimplemented('Contacts.pickContact() is not available on web.');\n }\n\n async pickContactField(_options: PickContactFieldOptions): Promise<PickedContactField> {\n throw this.unimplemented('Contacts.pickContactField() is not available on web.');\n }\n}\n"]}
@@ -25,6 +25,9 @@ class ContactsWeb extends core.WebPlugin {
25
25
  async pickContact() {
26
26
  throw this.unimplemented('Contacts.pickContact() is not available on web.');
27
27
  }
28
+ async pickContactField(_options) {
29
+ throw this.unimplemented('Contacts.pickContactField() is not available on web.');
30
+ }
28
31
  }
29
32
 
30
33
  var web = /*#__PURE__*/Object.freeze({
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Contacts = registerPlugin('Contacts', {\n web: () => import('./web').then((m) => new m.ContactsWeb()),\n});\nexport * from './definitions';\nexport { Contacts };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Web implementation. The browser has no standardized, broadly-available\n * contacts database API (the Contact Picker API is limited, gated, and\n * read-only), so every method throws `unimplemented()`. The plugin is\n * native-only on iOS and Android.\n */\nexport class ContactsWeb extends WebPlugin {\n async find(_options) {\n throw this.unimplemented('Contacts.find() is not available on web.');\n }\n async save(_options) {\n throw this.unimplemented('Contacts.save() is not available on web.');\n }\n async remove(_options) {\n throw this.unimplemented('Contacts.remove() is not available on web.');\n }\n async pickContact() {\n throw this.unimplemented('Contacts.pickContact() is not available on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,QAAQ,GAAGA,mBAAc,CAAC,UAAU,EAAE;AAC5C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAC/D,CAAC;;ACFD;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,WAAW,SAASC,cAAS,CAAC;AAC3C,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;AACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC;AAC5E,IAAI;AACJ,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;AACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC;AAC5E,IAAI;AACJ,IAAI,MAAM,MAAM,CAAC,QAAQ,EAAE;AAC3B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC;AAC9E,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC;AACnF,IAAI;AACJ;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Contacts = registerPlugin('Contacts', {\n web: () => import('./web').then((m) => new m.ContactsWeb()),\n});\nexport * from './definitions';\nexport { Contacts };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Web implementation. The browser has no standardized, broadly-available\n * contacts database API (the Contact Picker API is limited, gated, and\n * read-only), so every method throws `unimplemented()`. The plugin is\n * native-only on iOS and Android.\n */\nexport class ContactsWeb extends WebPlugin {\n async find(_options) {\n throw this.unimplemented('Contacts.find() is not available on web.');\n }\n async save(_options) {\n throw this.unimplemented('Contacts.save() is not available on web.');\n }\n async remove(_options) {\n throw this.unimplemented('Contacts.remove() is not available on web.');\n }\n async pickContact() {\n throw this.unimplemented('Contacts.pickContact() is not available on web.');\n }\n async pickContactField(_options) {\n throw this.unimplemented('Contacts.pickContactField() is not available on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,QAAQ,GAAGA,mBAAc,CAAC,UAAU,EAAE;AAC5C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAC/D,CAAC;;ACFD;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,WAAW,SAASC,cAAS,CAAC;AAC3C,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;AACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC;AAC5E,IAAI;AACJ,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;AACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC;AAC5E,IAAI;AACJ,IAAI,MAAM,MAAM,CAAC,QAAQ,EAAE;AAC3B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC;AAC9E,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC;AACnF,IAAI;AACJ,IAAI,MAAM,gBAAgB,CAAC,QAAQ,EAAE;AACrC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,sDAAsD,CAAC;AACxF,IAAI;AACJ;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -24,6 +24,9 @@ var capacitorContacts = (function (exports, core) {
24
24
  async pickContact() {
25
25
  throw this.unimplemented('Contacts.pickContact() is not available on web.');
26
26
  }
27
+ async pickContactField(_options) {
28
+ throw this.unimplemented('Contacts.pickContactField() is not available on web.');
29
+ }
27
30
  }
28
31
 
29
32
  var web = /*#__PURE__*/Object.freeze({
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Contacts = registerPlugin('Contacts', {\n web: () => import('./web').then((m) => new m.ContactsWeb()),\n});\nexport * from './definitions';\nexport { Contacts };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Web implementation. The browser has no standardized, broadly-available\n * contacts database API (the Contact Picker API is limited, gated, and\n * read-only), so every method throws `unimplemented()`. The plugin is\n * native-only on iOS and Android.\n */\nexport class ContactsWeb extends WebPlugin {\n async find(_options) {\n throw this.unimplemented('Contacts.find() is not available on web.');\n }\n async save(_options) {\n throw this.unimplemented('Contacts.save() is not available on web.');\n }\n async remove(_options) {\n throw this.unimplemented('Contacts.remove() is not available on web.');\n }\n async pickContact() {\n throw this.unimplemented('Contacts.pickContact() is not available on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,QAAQ,GAAGA,mBAAc,CAAC,UAAU,EAAE;IAC5C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/D,CAAC;;ICFD;IACA;IACA;IACA;IACA;IACA;IACO,MAAM,WAAW,SAASC,cAAS,CAAC;IAC3C,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;IACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC;IAC5E,IAAI;IACJ,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;IACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC;IAC5E,IAAI;IACJ,IAAI,MAAM,MAAM,CAAC,QAAQ,EAAE;IAC3B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC;IAC9E,IAAI;IACJ,IAAI,MAAM,WAAW,GAAG;IACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC;IACnF,IAAI;IACJ;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Contacts = registerPlugin('Contacts', {\n web: () => import('./web').then((m) => new m.ContactsWeb()),\n});\nexport * from './definitions';\nexport { Contacts };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Web implementation. The browser has no standardized, broadly-available\n * contacts database API (the Contact Picker API is limited, gated, and\n * read-only), so every method throws `unimplemented()`. The plugin is\n * native-only on iOS and Android.\n */\nexport class ContactsWeb extends WebPlugin {\n async find(_options) {\n throw this.unimplemented('Contacts.find() is not available on web.');\n }\n async save(_options) {\n throw this.unimplemented('Contacts.save() is not available on web.');\n }\n async remove(_options) {\n throw this.unimplemented('Contacts.remove() is not available on web.');\n }\n async pickContact() {\n throw this.unimplemented('Contacts.pickContact() is not available on web.');\n }\n async pickContactField(_options) {\n throw this.unimplemented('Contacts.pickContactField() is not available on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,QAAQ,GAAGA,mBAAc,CAAC,UAAU,EAAE;IAC5C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/D,CAAC;;ICFD;IACA;IACA;IACA;IACA;IACA;IACO,MAAM,WAAW,SAASC,cAAS,CAAC;IAC3C,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;IACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC;IAC5E,IAAI;IACJ,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;IACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC;IAC5E,IAAI;IACJ,IAAI,MAAM,MAAM,CAAC,QAAQ,EAAE;IAC3B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC;IAC9E,IAAI;IACJ,IAAI,MAAM,WAAW,GAAG;IACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC;IACnF,IAAI;IACJ,IAAI,MAAM,gBAAgB,CAAC,QAAQ,EAAE;IACrC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,sDAAsD,CAAC;IACxF,IAAI;IACJ;;;;;;;;;;;"}
@@ -132,14 +132,25 @@ extension Contacts {
132
132
  address["pref"] = false
133
133
  address["type"] = canonicalLabel(labeled.label)
134
134
  address["formatted"] = CNPostalAddressFormatter.string(from: postal, style: .mailingAddress)
135
- address["streetAddress"] = postal.street
136
- address["locality"] = postal.city
137
- address["region"] = postal.state
138
- address["postalCode"] = postal.postalCode
139
- address["country"] = postal.country
135
+ address.merge(postalParts(postal)) { _, new in new }
140
136
  return address
141
137
  }
142
138
 
139
+ /// The postal parts of a `CNPostalAddress`, shared by the full-contact and
140
+ /// picked-field results.
141
+ ///
142
+ /// - Parameter postal: the address to read.
143
+ /// - Returns: `streetAddress`, `locality`, `region`, `postalCode` and `country`.
144
+ private func postalParts(_ postal: CNPostalAddress) -> [String: Any] {
145
+ return [
146
+ "streetAddress": postal.street,
147
+ "locality": postal.city,
148
+ "region": postal.state,
149
+ "postalCode": postal.postalCode,
150
+ "country": postal.country
151
+ ]
152
+ }
153
+
143
154
  private func field(id: String?, value: String, type: String) -> [String: Any] {
144
155
  var result: [String: Any] = [:]
145
156
  if let id = id { result["id"] = id }
@@ -175,6 +186,57 @@ extension Contacts {
175
186
  }
176
187
  }
177
188
 
189
+ // MARK: - Mapping a picked contact property -> dictionary
190
+
191
+ /// The `CNContact` key behind each `pickContactField` kind.
192
+ ///
193
+ /// - Parameter field: `phone`, `email` or `address`.
194
+ /// - Returns: the matching `CNContact` key, or `nil` for an unknown kind.
195
+ func pickerPropertyKey(forField field: String) -> String? {
196
+ switch field {
197
+ case "phone": return CNContactPhoneNumbersKey
198
+ case "email": return CNContactEmailAddressesKey
199
+ case "address": return CNContactPostalAddressesKey
200
+ default: return nil
201
+ }
202
+ }
203
+
204
+ /// Maps the property the user tapped in the system picker to the
205
+ /// `pickContactField` result: the picked `value` and its `type` label, plus
206
+ /// the contact's `displayName` when available. Same shape Android returns.
207
+ ///
208
+ /// - Parameters:
209
+ /// - contact: the contact the property belongs to.
210
+ /// - key: the `CNContact` key of the tapped property.
211
+ /// - label: the property's label, e.g. `CNLabelHome`.
212
+ /// - value: the property's value (`CNPhoneNumber`, `String` or `CNPostalAddress`).
213
+ /// - Returns: the result dictionary, or `nil` when `value` isn't the type
214
+ /// expected for `key`.
215
+ func pickedPropertyToDictionary(contact: CNContact, key: String, label: String?, value: Any) -> [String: Any]? {
216
+ var dict: [String: Any] = [:]
217
+ switch (key, value) {
218
+ case (CNContactPhoneNumbersKey, let phone as CNPhoneNumber):
219
+ dict["field"] = "phone"
220
+ dict["value"] = phone.stringValue
221
+ case (CNContactEmailAddressesKey, let email as String):
222
+ dict["field"] = "email"
223
+ dict["value"] = email
224
+ case (CNContactPostalAddressesKey, let postal as CNPostalAddress):
225
+ dict["field"] = "address"
226
+ dict["value"] = CNPostalAddressFormatter.string(from: postal, style: .mailingAddress)
227
+ dict["address"] = postalParts(postal)
228
+ default:
229
+ return nil
230
+ }
231
+ dict["type"] = canonicalLabel(label)
232
+ let fullName = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName)]
233
+ if contact.areKeysAvailable(fullName),
234
+ let name = CNContactFormatter.string(from: contact, style: .fullName), !name.isEmpty {
235
+ dict["displayName"] = name
236
+ }
237
+ return dict
238
+ }
239
+
178
240
  // MARK: - Mapping dictionary -> CNMutableContact
179
241
 
180
242
  func apply(_ dict: [String: Any], to contact: CNMutableContact) {
@@ -8,8 +8,8 @@ import Foundation
8
8
  /// Permission model is **implicit**: there are no `checkPermissions` /
9
9
  /// `requestPermissions` methods. `find`, `save` and `remove` request Contacts
10
10
  /// access before touching the store. On iOS 18+ Limited Access counts as
11
- /// granted. `pickContact` presents the system picker, which requires no
12
- /// permission at all.
11
+ /// granted. `pickContact` and `pickContactField` present the system picker,
12
+ /// which requires no permission at all.
13
13
  @objc(ContactsPlugin)
14
14
  public class ContactsPlugin: CAPPlugin, CAPBridgedPlugin {
15
15
  public let identifier = "ContactsPlugin"
@@ -18,7 +18,8 @@ public class ContactsPlugin: CAPPlugin, CAPBridgedPlugin {
18
18
  CAPPluginMethod(name: "find", returnType: CAPPluginReturnPromise),
19
19
  CAPPluginMethod(name: "save", returnType: CAPPluginReturnPromise),
20
20
  CAPPluginMethod(name: "remove", returnType: CAPPluginReturnPromise),
21
- CAPPluginMethod(name: "pickContact", returnType: CAPPluginReturnPromise)
21
+ CAPPluginMethod(name: "pickContact", returnType: CAPPluginReturnPromise),
22
+ CAPPluginMethod(name: "pickContactField", returnType: CAPPluginReturnPromise)
22
23
  ]
23
24
 
24
25
  private let implementation = Contacts()
@@ -26,6 +27,10 @@ public class ContactsPlugin: CAPPlugin, CAPBridgedPlugin {
26
27
  /// Call awaiting the result of the contact picker UI.
27
28
  private var pickCall: CAPPluginCall?
28
29
 
30
+ /// Delegate of the in-flight `pickContactField` picker. Held here because
31
+ /// `CNContactPickerViewController.delegate` is a weak reference.
32
+ private var fieldPickerDelegate: FieldPickerDelegate?
33
+
29
34
  // MARK: - find
30
35
 
31
36
  @objc func find(_ call: CAPPluginCall) {
@@ -107,14 +112,84 @@ public class ContactsPlugin: CAPPlugin, CAPBridgedPlugin {
107
112
  self.pickCall = call
108
113
  let picker = CNContactPickerViewController()
109
114
  picker.delegate = self
110
- // Present from the top-most controller so an already-presented
111
- // modal doesn't make present() fail silently (stuck pick state).
112
- var presenter = viewController
113
- while let presented = presenter.presentedViewController {
114
- presenter = presented
115
+ self.present(picker, from: viewController)
116
+ }
117
+ }
118
+
119
+ // MARK: - pickContactField
120
+
121
+ /// Presents the system picker restricted to one kind of property (phone,
122
+ /// email or address), so the user taps a single value and only that value
123
+ /// plus the contact's name is returned. Needs no Contacts permission.
124
+ ///
125
+ /// - Parameter call: carries the `field` option. Rejects with
126
+ /// `OS-PLUG-CONT-0001` when it is missing or unknown.
127
+ @objc func pickContactField(_ call: CAPPluginCall) {
128
+ guard let field = call.getString("field"),
129
+ let key = implementation.pickerPropertyKey(forField: field) else {
130
+ reject(call, .invalidArgument)
131
+ return
132
+ }
133
+ DispatchQueue.main.async {
134
+ guard self.pickCall == nil else {
135
+ self.reject(call, .pendingOperation)
136
+ return
137
+ }
138
+ guard let viewController = self.bridge?.viewController else {
139
+ self.reject(call, .unknown)
140
+ return
115
141
  }
116
- presenter.present(picker, animated: true)
142
+ self.pickCall = call
143
+ let delegate = FieldPickerDelegate(
144
+ onSelect: { [weak self] property in
145
+ guard let self = self, let call = self.finishPick() else { return }
146
+ if let contact = self.implementation.pickedPropertyToDictionary(
147
+ contact: property.contact,
148
+ key: property.key,
149
+ label: property.label,
150
+ value: property.value as Any
151
+ ) {
152
+ call.resolve(contact)
153
+ } else {
154
+ self.reject(call, .unknown)
155
+ }
156
+ },
157
+ onCancel: { [weak self] in
158
+ guard let self = self, let call = self.finishPick() else { return }
159
+ self.reject(call, .operationCancelled)
160
+ }
161
+ )
162
+ self.fieldPickerDelegate = delegate
163
+ let picker = CNContactPickerViewController()
164
+ picker.displayedPropertyKeys = [key]
165
+ picker.predicateForSelectionOfProperty = NSPredicate(format: "key == %@", key)
166
+ picker.delegate = delegate
167
+ self.present(picker, from: viewController)
168
+ }
169
+ }
170
+
171
+ /// Clears the in-flight pick state.
172
+ ///
173
+ /// - Returns: the call the pick was holding.
174
+ private func finishPick() -> CAPPluginCall? {
175
+ let call = pickCall
176
+ pickCall = nil
177
+ fieldPickerDelegate = nil
178
+ return call
179
+ }
180
+
181
+ /// Presents from the top-most controller so an already-presented modal
182
+ /// doesn't make present() fail silently (stuck pick state).
183
+ ///
184
+ /// - Parameters:
185
+ /// - picker: the picker to show.
186
+ /// - viewController: the controller to start looking for a presenter from.
187
+ private func present(_ picker: CNContactPickerViewController, from viewController: UIViewController) {
188
+ var presenter = viewController
189
+ while let presented = presenter.presentedViewController {
190
+ presenter = presented
117
191
  }
192
+ presenter.present(picker, animated: true)
118
193
  }
119
194
 
120
195
  // MARK: - Implicit permission handling
@@ -164,3 +239,27 @@ extension ContactsPlugin: CNContactPickerDelegate {
164
239
  call?.reject(ContactsError.operationCancelled.message, ContactsError.operationCancelled.code)
165
240
  }
166
241
  }
242
+
243
+ /// Delegate for `pickContactField`. Implements only the property-selection
244
+ /// callback: also implementing `didSelect contact:` would make the picker
245
+ /// select whole contacts and never report a property.
246
+ private final class FieldPickerDelegate: NSObject, CNContactPickerDelegate {
247
+ private let onSelect: (CNContactProperty) -> Void
248
+ private let onCancel: () -> Void
249
+
250
+ /// - Parameters:
251
+ /// - onSelect: called with the property the user tapped.
252
+ /// - onCancel: called when the user dismisses the picker.
253
+ init(onSelect: @escaping (CNContactProperty) -> Void, onCancel: @escaping () -> Void) {
254
+ self.onSelect = onSelect
255
+ self.onCancel = onCancel
256
+ }
257
+
258
+ func contactPicker(_ picker: CNContactPickerViewController, didSelect contactProperty: CNContactProperty) {
259
+ onSelect(contactProperty)
260
+ }
261
+
262
+ func contactPickerDidCancel(_ picker: CNContactPickerViewController) {
263
+ onCancel()
264
+ }
265
+ }
@@ -66,4 +66,54 @@ class ContactsTests: XCTestCase {
66
66
  XCTAssertNil(dict["name"])
67
67
  XCTAssertNil(dict["displayName"])
68
68
  }
69
+
70
+ func testPickerPropertyKeyMapsFieldKinds() {
71
+ let contacts = Contacts()
72
+ XCTAssertEqual(contacts.pickerPropertyKey(forField: "phone"), CNContactPhoneNumbersKey)
73
+ XCTAssertEqual(contacts.pickerPropertyKey(forField: "email"), CNContactEmailAddressesKey)
74
+ XCTAssertEqual(contacts.pickerPropertyKey(forField: "address"), CNContactPostalAddressesKey)
75
+ XCTAssertNil(contacts.pickerPropertyKey(forField: "phoneNumbers"))
76
+ }
77
+
78
+ func testPickedPropertyReturnsOnlyTheValueTypeAndName() {
79
+ let contact = CNMutableContact()
80
+ contact.givenName = "Ada"
81
+ contact.familyName = "Lovelace"
82
+ contact.emailAddresses = [CNLabeledValue(label: CNLabelHome, value: "ada@example.com" as NSString)]
83
+
84
+ let dict = Contacts().pickedPropertyToDictionary(
85
+ contact: contact,
86
+ key: CNContactPhoneNumbersKey,
87
+ label: CNLabelWork,
88
+ value: CNPhoneNumber(stringValue: "+351920000000")
89
+ )
90
+
91
+ XCTAssertEqual(dict?["field"] as? String, "phone")
92
+ XCTAssertEqual(dict?["value"] as? String, "+351920000000")
93
+ XCTAssertEqual(dict?["type"] as? String, "work")
94
+ XCTAssertEqual(dict?["displayName"] as? String, "Ada Lovelace")
95
+ XCTAssertEqual(Set(dict?.keys.map { $0 } ?? []), ["field", "value", "type", "displayName"])
96
+ }
97
+
98
+ func testPickedPropertyMapsAddressAndRejectsMismatchedValue() {
99
+ let contact = CNMutableContact()
100
+ let postal = CNMutablePostalAddress()
101
+ postal.street = "1 Main St"
102
+ postal.city = "Lisbon"
103
+
104
+ let contacts = Contacts()
105
+ let dict = contacts.pickedPropertyToDictionary(
106
+ contact: contact, key: CNContactPostalAddressesKey, label: CNLabelHome, value: postal
107
+ )
108
+ XCTAssertEqual(dict?["field"] as? String, "address")
109
+ XCTAssertTrue((dict?["value"] as? String)?.contains("1 Main St") ?? false)
110
+ XCTAssertNil(dict?["displayName"])
111
+ let address = dict?["address"] as? [String: String]
112
+ XCTAssertEqual(address?["streetAddress"], "1 Main St")
113
+ XCTAssertEqual(address?["locality"], "Lisbon")
114
+
115
+ XCTAssertNil(contacts.pickedPropertyToDictionary(
116
+ contact: contact, key: CNContactPostalAddressesKey, label: nil, value: "not an address"
117
+ ))
118
+ }
69
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/contacts",
3
- "version": "1.0.2-next.1",
3
+ "version": "1.1.0",
4
4
  "description": "Access, search, pick, create, update and remove device contacts.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -38,13 +38,14 @@
38
38
  "verify:web": "npm run build",
39
39
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
40
40
  "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
41
- "eslint": "eslint .",
41
+ "eslint": "eslint . --ext ts",
42
42
  "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
43
43
  "swiftlint": "node-swiftlint",
44
44
  "docgen": "docgen --api ContactsPlugin --output-readme README.md --output-json dist/docs.json",
45
45
  "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
46
46
  "clean": "rimraf ./dist",
47
47
  "watch": "tsc --watch",
48
+ "prepare": "npm run build",
48
49
  "prepublishOnly": "npm run build",
49
50
  "publish:cocoapod": "pod trunk push ./CapacitorContacts.podspec --allow-warnings"
50
51
  },
@@ -53,10 +54,10 @@
53
54
  "@capacitor/core": "^8.0.0",
54
55
  "@capacitor/docgen": "^0.3.1",
55
56
  "@capacitor/ios": "^8.0.0",
56
- "@ionic/eslint-config": "^0.5.0",
57
+ "@ionic/eslint-config": "^0.4.0",
57
58
  "@ionic/prettier-config": "^4.0.0",
58
59
  "@ionic/swiftlint-config": "^2.0.0",
59
- "eslint": "^10.0.0",
60
+ "eslint": "^8.57.1",
60
61
  "prettier": "^3.6.2",
61
62
  "prettier-plugin-java": "^2.7.7",
62
63
  "rimraf": "^6.1.0",
@@ -74,6 +75,9 @@
74
75
  },
75
76
  "prettier": "@ionic/prettier-config",
76
77
  "swiftlint": "@ionic/swiftlint-config",
78
+ "eslintConfig": {
79
+ "extends": "@ionic/eslint-config/recommended"
80
+ },
77
81
  "capacitor": {
78
82
  "ios": {
79
83
  "src": "ios"