@capgo/capacitor-contacts 8.0.2 → 8.0.4
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.
|
@@ -5,7 +5,7 @@ import UIKit
|
|
|
5
5
|
|
|
6
6
|
@objc(CapacitorContactsPlugin)
|
|
7
7
|
public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
8
|
-
private let pluginVersion: String = "8.0.
|
|
8
|
+
private let pluginVersion: String = "8.0.4"
|
|
9
9
|
public let identifier = "CapacitorContactsPlugin"
|
|
10
10
|
public let jsName = "CapacitorContacts"
|
|
11
11
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -54,10 +54,9 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
54
54
|
|
|
55
55
|
@objc func getContacts(_ call: CAPPluginCall) {
|
|
56
56
|
ensureAuthorized(call) {
|
|
57
|
-
let
|
|
58
|
-
let
|
|
59
|
-
let
|
|
60
|
-
let offset = options["offset"] as? Int ?? 0
|
|
57
|
+
let fields = (call.options["fields"] as? [String]).map { Set($0) }
|
|
58
|
+
let limit = call.options["limit"] as? Int
|
|
59
|
+
let offset = call.options["offset"] as? Int ?? 0
|
|
61
60
|
|
|
62
61
|
let keysToFetch = self.keysToFetch(for: fields)
|
|
63
62
|
let request = CNContactFetchRequest(keysToFetch: keysToFetch)
|
|
@@ -95,13 +94,13 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
@objc func getContactById(_ call: CAPPluginCall) {
|
|
98
|
-
guard let
|
|
97
|
+
guard let identifier = call.options["id"] as? String else {
|
|
99
98
|
call.reject("Missing contact identifier.")
|
|
100
99
|
return
|
|
101
100
|
}
|
|
102
101
|
|
|
103
102
|
ensureAuthorized(call) {
|
|
104
|
-
let fields = (options["fields"] as? [String]).map { Set($0) }
|
|
103
|
+
let fields = (call.options["fields"] as? [String]).map { Set($0) }
|
|
105
104
|
let keysToFetch = self.keysToFetch(for: fields)
|
|
106
105
|
|
|
107
106
|
do {
|
|
@@ -164,7 +163,7 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
@objc override public func requestPermissions(_ call: CAPPluginCall) {
|
|
167
|
-
let requested = (call.options["
|
|
166
|
+
let requested = (call.options["permissions"] as? [String]) ?? ["readContacts", "writeContacts"]
|
|
168
167
|
let needsRequest = requested.contains { _ in mapAuthorizationStatus(CNContactStore.authorizationStatus(for: .contacts)) != "granted" }
|
|
169
168
|
|
|
170
169
|
if !needsRequest {
|
|
@@ -187,8 +186,7 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
187
186
|
// MARK: - Write operations
|
|
188
187
|
|
|
189
188
|
@objc func createContact(_ call: CAPPluginCall) {
|
|
190
|
-
guard let
|
|
191
|
-
let contactData = options["contact"] as? JSObject else {
|
|
189
|
+
guard let contactData = call.options["contact"] as? JSObject else {
|
|
192
190
|
call.reject("Missing contact data.")
|
|
193
191
|
return
|
|
194
192
|
}
|
|
@@ -210,16 +208,15 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
210
208
|
}
|
|
211
209
|
|
|
212
210
|
@objc func updateContactById(_ call: CAPPluginCall) {
|
|
213
|
-
guard let
|
|
214
|
-
let
|
|
215
|
-
let contactData = options["contact"] as? JSObject else {
|
|
211
|
+
guard let identifier = call.options["id"] as? String,
|
|
212
|
+
let contactData = call.options["contact"] as? JSObject else {
|
|
216
213
|
call.reject("Missing contact identifier or data.")
|
|
217
214
|
return
|
|
218
215
|
}
|
|
219
216
|
|
|
220
217
|
ensureAuthorized(call) {
|
|
221
218
|
do {
|
|
222
|
-
|
|
219
|
+
var keysToFetch: [CNKeyDescriptor] = [
|
|
223
220
|
CNContactIdentifierKey as CNKeyDescriptor,
|
|
224
221
|
CNContactGivenNameKey as CNKeyDescriptor,
|
|
225
222
|
CNContactFamilyNameKey as CNKeyDescriptor,
|
|
@@ -233,10 +230,13 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
233
230
|
CNContactPostalAddressesKey as CNKeyDescriptor,
|
|
234
231
|
CNContactUrlAddressesKey as CNKeyDescriptor,
|
|
235
232
|
CNContactBirthdayKey as CNKeyDescriptor,
|
|
236
|
-
CNContactNoteKey as CNKeyDescriptor,
|
|
237
233
|
CNContactImageDataKey as CNKeyDescriptor
|
|
238
234
|
]
|
|
239
235
|
|
|
236
|
+
if contactData["note"] != nil {
|
|
237
|
+
keysToFetch.append(CNContactNoteKey as CNKeyDescriptor)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
240
|
let contact = try self.contactStore.unifiedContact(withIdentifier: identifier, keysToFetch: keysToFetch)
|
|
241
241
|
let mutableContact = contact.mutableCopy() as! CNMutableContact
|
|
242
242
|
|
|
@@ -254,8 +254,7 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
@objc func deleteContactById(_ call: CAPPluginCall) {
|
|
257
|
-
guard let
|
|
258
|
-
let identifier = options["id"] as? String else {
|
|
257
|
+
guard let identifier = call.options["id"] as? String else {
|
|
259
258
|
call.reject("Missing contact identifier.")
|
|
260
259
|
return
|
|
261
260
|
}
|
|
@@ -297,8 +296,7 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
297
296
|
}
|
|
298
297
|
|
|
299
298
|
@objc func getGroupById(_ call: CAPPluginCall) {
|
|
300
|
-
guard let
|
|
301
|
-
let identifier = options["id"] as? String else {
|
|
299
|
+
guard let identifier = call.options["id"] as? String else {
|
|
302
300
|
call.reject("Missing group identifier.")
|
|
303
301
|
return
|
|
304
302
|
}
|
|
@@ -321,8 +319,7 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
321
319
|
}
|
|
322
320
|
|
|
323
321
|
@objc func createGroup(_ call: CAPPluginCall) {
|
|
324
|
-
guard let
|
|
325
|
-
let groupData = options["group"] as? JSObject,
|
|
322
|
+
guard let groupData = call.options["group"] as? JSObject,
|
|
326
323
|
let name = groupData["name"] as? String else {
|
|
327
324
|
call.reject("Missing group name.")
|
|
328
325
|
return
|
|
@@ -345,8 +342,7 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
345
342
|
}
|
|
346
343
|
|
|
347
344
|
@objc func deleteGroupById(_ call: CAPPluginCall) {
|
|
348
|
-
guard let
|
|
349
|
-
let identifier = options["id"] as? String else {
|
|
345
|
+
guard let identifier = call.options["id"] as? String else {
|
|
350
346
|
call.reject("Missing group identifier.")
|
|
351
347
|
return
|
|
352
348
|
}
|
|
@@ -392,8 +388,7 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
392
388
|
}
|
|
393
389
|
|
|
394
390
|
@objc func displayContactById(_ call: CAPPluginCall) {
|
|
395
|
-
guard let
|
|
396
|
-
let identifier = options["id"] as? String else {
|
|
391
|
+
guard let identifier = call.options["id"] as? String else {
|
|
397
392
|
call.reject("Missing contact identifier.")
|
|
398
393
|
return
|
|
399
394
|
}
|
|
@@ -420,8 +415,7 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
420
415
|
DispatchQueue.main.async {
|
|
421
416
|
let newContact = CNMutableContact()
|
|
422
417
|
|
|
423
|
-
if let
|
|
424
|
-
let contactData = options["contact"] as? JSObject {
|
|
418
|
+
if let contactData = call.options["contact"] as? JSObject {
|
|
425
419
|
self.populateContact(newContact, from: contactData)
|
|
426
420
|
}
|
|
427
421
|
|
|
@@ -436,8 +430,7 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
436
430
|
}
|
|
437
431
|
|
|
438
432
|
@objc func displayUpdateContactById(_ call: CAPPluginCall) {
|
|
439
|
-
guard let
|
|
440
|
-
let identifier = options["id"] as? String else {
|
|
433
|
+
guard let identifier = call.options["id"] as? String else {
|
|
441
434
|
call.reject("Missing contact identifier.")
|
|
442
435
|
return
|
|
443
436
|
}
|
|
@@ -515,29 +508,35 @@ public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
515
508
|
|
|
516
509
|
private func keysToFetch(for fields: Set<String>?) -> [CNKeyDescriptor] {
|
|
517
510
|
var keys: [CNKeyDescriptor] = [
|
|
518
|
-
CNContactIdentifierKey as CNKeyDescriptor
|
|
519
|
-
CNContactGivenNameKey as CNKeyDescriptor,
|
|
520
|
-
CNContactFamilyNameKey as CNKeyDescriptor,
|
|
521
|
-
CNContactMiddleNameKey as CNKeyDescriptor,
|
|
522
|
-
CNContactNamePrefixKey as CNKeyDescriptor,
|
|
523
|
-
CNContactNameSuffixKey as CNKeyDescriptor,
|
|
524
|
-
CNContactOrganizationNameKey as CNKeyDescriptor,
|
|
525
|
-
CNContactJobTitleKey as CNKeyDescriptor,
|
|
526
|
-
CNContactEmailAddressesKey as CNKeyDescriptor,
|
|
527
|
-
CNContactPhoneNumbersKey as CNKeyDescriptor,
|
|
528
|
-
CNContactPostalAddressesKey as CNKeyDescriptor,
|
|
529
|
-
CNContactUrlAddressesKey as CNKeyDescriptor,
|
|
530
|
-
CNContactBirthdayKey as CNKeyDescriptor,
|
|
531
|
-
CNContactNoteKey as CNKeyDescriptor,
|
|
532
|
-
CNContactImageDataAvailableKey as CNKeyDescriptor,
|
|
533
|
-
CNContactImageDataKey as CNKeyDescriptor
|
|
511
|
+
CNContactIdentifierKey as CNKeyDescriptor
|
|
534
512
|
]
|
|
535
513
|
|
|
514
|
+
let shouldFetchAll = fields == nil
|
|
515
|
+
|
|
516
|
+
if shouldFetchAll || fields!.contains("givenName") { keys.append(CNContactGivenNameKey as CNKeyDescriptor) }
|
|
517
|
+
if shouldFetchAll || fields!.contains("familyName") { keys.append(CNContactFamilyNameKey as CNKeyDescriptor) }
|
|
518
|
+
if shouldFetchAll || fields!.contains("middleName") { keys.append(CNContactMiddleNameKey as CNKeyDescriptor) }
|
|
519
|
+
if shouldFetchAll || fields!.contains("namePrefix") { keys.append(CNContactNamePrefixKey as CNKeyDescriptor) }
|
|
520
|
+
if shouldFetchAll || fields!.contains("nameSuffix") { keys.append(CNContactNameSuffixKey as CNKeyDescriptor) }
|
|
521
|
+
if shouldFetchAll || fields!.contains("organizationName") { keys.append(CNContactOrganizationNameKey as CNKeyDescriptor) }
|
|
522
|
+
if shouldFetchAll || fields!.contains("jobTitle") { keys.append(CNContactJobTitleKey as CNKeyDescriptor) }
|
|
523
|
+
if shouldFetchAll || fields!.contains("emailAddresses") { keys.append(CNContactEmailAddressesKey as CNKeyDescriptor) }
|
|
524
|
+
if shouldFetchAll || fields!.contains("phoneNumbers") { keys.append(CNContactPhoneNumbersKey as CNKeyDescriptor) }
|
|
525
|
+
if shouldFetchAll || fields!.contains("postalAddresses") { keys.append(CNContactPostalAddressesKey as CNKeyDescriptor) }
|
|
526
|
+
if shouldFetchAll || fields!.contains("urlAddresses") { keys.append(CNContactUrlAddressesKey as CNKeyDescriptor) }
|
|
527
|
+
if shouldFetchAll || fields!.contains("birthday") { keys.append(CNContactBirthdayKey as CNKeyDescriptor) }
|
|
528
|
+
if shouldFetchAll || fields!.contains("note") { keys.append(CNContactNoteKey as CNKeyDescriptor) }
|
|
529
|
+
|
|
530
|
+
if shouldFetchAll || fields!.contains("photo") {
|
|
531
|
+
keys.append(CNContactImageDataAvailableKey as CNKeyDescriptor)
|
|
532
|
+
keys.append(CNContactImageDataKey as CNKeyDescriptor)
|
|
533
|
+
}
|
|
534
|
+
|
|
536
535
|
if let fields, fields.contains("groupIds") {
|
|
537
536
|
// No additional keys required, but this preserves the behaviour if custom keys are needed later.
|
|
538
537
|
}
|
|
539
538
|
|
|
540
|
-
if
|
|
539
|
+
if shouldFetchAll || fields!.contains("fullName") {
|
|
541
540
|
keys.append(CNContactFormatter.descriptorForRequiredKeys(for: .fullName))
|
|
542
541
|
}
|
|
543
542
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-contacts",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.4",
|
|
4
4
|
"description": "Work with device contacts using Capacitor APIs",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
44
44
|
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
45
45
|
"eslint": "eslint . --ext .ts",
|
|
46
|
-
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
46
|
+
"prettier": "prettier-pretty-check \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
47
47
|
"swiftlint": "node-swiftlint",
|
|
48
48
|
"docgen": "docgen --api CapacitorContactsPlugin --output-readme README.md --output-json dist/docs.json",
|
|
49
49
|
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
@@ -69,7 +69,8 @@
|
|
|
69
69
|
"rimraf": "^6.1.0",
|
|
70
70
|
"rollup": "^4.53.2",
|
|
71
71
|
"swiftlint": "^2.0.0",
|
|
72
|
-
"typescript": "^5.9.3"
|
|
72
|
+
"typescript": "^5.9.3",
|
|
73
|
+
"prettier-pretty-check": "^0.2.0"
|
|
73
74
|
},
|
|
74
75
|
"peerDependencies": {
|
|
75
76
|
"@capacitor/core": ">=8.0.0"
|