@capacitor/contacts 1.1.0-dev.1 → 2.0.0-next.1

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.
@@ -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` and `pickContactField` present the system picker,
12
- /// which requires no permission at all.
11
+ /// granted. `pickContact` presents the system picker, which requires no
12
+ /// permission at all.
13
13
  @objc(ContactsPlugin)
14
14
  public class ContactsPlugin: CAPPlugin, CAPBridgedPlugin {
15
15
  public let identifier = "ContactsPlugin"
@@ -18,8 +18,7 @@ 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),
22
- CAPPluginMethod(name: "pickContactField", returnType: CAPPluginReturnPromise)
21
+ CAPPluginMethod(name: "pickContact", returnType: CAPPluginReturnPromise)
23
22
  ]
24
23
 
25
24
  private let implementation = Contacts()
@@ -27,10 +26,6 @@ public class ContactsPlugin: CAPPlugin, CAPBridgedPlugin {
27
26
  /// Call awaiting the result of the contact picker UI.
28
27
  private var pickCall: CAPPluginCall?
29
28
 
30
- /// Delegate of the in-flight `pickContactField` picker. Held here because
31
- /// `CNContactPickerViewController.delegate` is a weak reference.
32
- private var fieldPickerDelegate: FieldPickerDelegate?
33
-
34
29
  // MARK: - find
35
30
 
36
31
  @objc func find(_ call: CAPPluginCall) {
@@ -112,84 +107,14 @@ public class ContactsPlugin: CAPPlugin, CAPBridgedPlugin {
112
107
  self.pickCall = call
113
108
  let picker = CNContactPickerViewController()
114
109
  picker.delegate = self
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
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
141
115
  }
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
116
+ presenter.present(picker, animated: true)
191
117
  }
192
- presenter.present(picker, animated: true)
193
118
  }
194
119
 
195
120
  // MARK: - Implicit permission handling
@@ -239,27 +164,3 @@ extension ContactsPlugin: CNContactPickerDelegate {
239
164
  call?.reject(ContactsError.operationCancelled.message, ContactsError.operationCancelled.code)
240
165
  }
241
166
  }
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,54 +66,4 @@ 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
- }
119
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/contacts",
3
- "version": "1.1.0-dev.1",
3
+ "version": "2.0.0-next.1",
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",
@@ -15,7 +15,8 @@
15
15
  "android/src/main/",
16
16
  "dist/",
17
17
  "ios/Sources",
18
- "ios/Tests"
18
+ "ios/Tests",
19
+ "android/proguard-rules.pro"
19
20
  ],
20
21
  "author": "OutSystems <support@outsystems.com>",
21
22
  "license": "MIT",
@@ -38,26 +39,25 @@
38
39
  "verify:web": "npm run build",
39
40
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
40
41
  "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
41
- "eslint": "eslint . --ext ts",
42
+ "eslint": "eslint .",
42
43
  "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
43
44
  "swiftlint": "node-swiftlint",
44
45
  "docgen": "docgen --api ContactsPlugin --output-readme README.md --output-json dist/docs.json",
45
46
  "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
46
47
  "clean": "rimraf ./dist",
47
48
  "watch": "tsc --watch",
48
- "prepare": "npm run build",
49
49
  "prepublishOnly": "npm run build",
50
50
  "publish:cocoapod": "pod trunk push ./CapacitorContacts.podspec --allow-warnings"
51
51
  },
52
52
  "devDependencies": {
53
- "@capacitor/android": "^8.0.0",
54
- "@capacitor/core": "^8.0.0",
53
+ "@capacitor/android": "next",
54
+ "@capacitor/core": "next",
55
55
  "@capacitor/docgen": "^0.3.1",
56
- "@capacitor/ios": "^8.0.0",
57
- "@ionic/eslint-config": "^0.4.0",
56
+ "@capacitor/ios": "next",
57
+ "@ionic/eslint-config": "^0.5.0",
58
58
  "@ionic/prettier-config": "^4.0.0",
59
59
  "@ionic/swiftlint-config": "^2.0.0",
60
- "eslint": "^8.57.1",
60
+ "eslint": "^10.0.0",
61
61
  "prettier": "^3.6.2",
62
62
  "prettier-plugin-java": "^2.7.7",
63
63
  "rimraf": "^6.1.0",
@@ -71,13 +71,10 @@
71
71
  "semantic-release": "^25.0.2"
72
72
  },
73
73
  "peerDependencies": {
74
- "@capacitor/core": ">=8.0.0"
74
+ "@capacitor/core": ">=9.0.0-beta.0"
75
75
  },
76
76
  "prettier": "@ionic/prettier-config",
77
77
  "swiftlint": "@ionic/swiftlint-config",
78
- "eslintConfig": {
79
- "extends": "@ionic/eslint-config/recommended"
80
- },
81
78
  "capacitor": {
82
79
  "ios": {
83
80
  "src": "ios"
@@ -1,17 +0,0 @@
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
- }