@aalzehla/capacitor-contacts 0.0.5 → 8.0.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.
- package/AalzehlaCapacitorContacts.podspec +2 -2
- package/README.md +69 -45
- package/android/build.gradle +15 -12
- package/android/src/main/java/getcapacitor/community/contacts/BiMap.java +45 -0
- package/android/src/main/java/getcapacitor/community/contacts/ContactPayload.java +286 -0
- package/android/src/main/java/getcapacitor/community/contacts/Contacts.java +384 -0
- package/android/src/main/java/getcapacitor/community/contacts/ContactsPlugin.java +255 -0
- package/android/src/main/java/getcapacitor/community/contacts/CreateContactInput.java +233 -0
- package/android/src/main/java/getcapacitor/community/contacts/GetContactsProjectionInput.java +214 -0
- package/dist/esm/definitions.d.ts +285 -19
- package/dist/esm/definitions.js +47 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +9 -7
- package/dist/esm/web.js +21 -7
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +73 -14
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +74 -15
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/BiMap.swift +42 -0
- package/ios/Plugin/ContactPayload.swift +227 -0
- package/ios/Plugin/Contacts.swift +227 -0
- package/ios/Plugin/ContactsPlugin.h +10 -0
- package/ios/Plugin/ContactsPlugin.m +14 -0
- package/ios/Plugin/ContactsPlugin.swift +221 -0
- package/ios/Plugin/CreateContactInput.swift +187 -0
- package/ios/Plugin/GetContactsProjectionInput.swift +119 -0
- package/ios/Plugin/Info.plist +24 -0
- package/package.json +32 -29
- package/Package.swift +0 -28
- package/android/src/main/java/com/aalzehla/capacitor/contacts/CapacitorContactsPlugin.java +0 -177
- package/android/src/main/java/com/aalzehla/capacitor/contacts/ContactDataExtractorVisitor.java +0 -122
- package/android/src/main/java/com/aalzehla/capacitor/contacts/ContactExtractorVisitor.java +0 -31
- package/android/src/main/java/com/aalzehla/capacitor/contacts/PluginContactFields.java +0 -17
- package/android/src/main/java/com/aalzehla/capacitor/contacts/contentQuery/ContentQuery.java +0 -83
- package/android/src/main/java/com/aalzehla/capacitor/contacts/contentQuery/ContentQueryService.java +0 -60
- package/android/src/main/java/com/aalzehla/capacitor/contacts/utils/Utils.java +0 -19
- package/android/src/main/java/com/aalzehla/capacitor/contacts/utils/Visitable.java +0 -5
- package/android/src/main/java/com/aalzehla/capacitor/contacts/utils/Visitor.java +0 -5
- package/dist/docs.json +0 -145
- package/ios/Sources/CapacitorContactsPlugin/CapacitorContactsPlugin.swift +0 -168
- package/ios/Tests/CapacitorContactsPluginTests/CapacitorContactsPluginTests.swift +0 -15
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import Contacts
|
|
4
|
+
import ContactsUI
|
|
5
|
+
|
|
6
|
+
enum CallingMethod {
|
|
7
|
+
case GetContact
|
|
8
|
+
case GetContacts
|
|
9
|
+
case CreateContact
|
|
10
|
+
case DeleteContact
|
|
11
|
+
case PickContact
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@objc(ContactsPlugin)
|
|
15
|
+
public class ContactsPlugin: CAPPlugin, CNContactPickerDelegate {
|
|
16
|
+
private let implementation = Contacts()
|
|
17
|
+
|
|
18
|
+
private var callingMethod: CallingMethod?
|
|
19
|
+
|
|
20
|
+
private var pickContactCallbackId: String?
|
|
21
|
+
|
|
22
|
+
@objc override public func checkPermissions(_ call: CAPPluginCall) {
|
|
23
|
+
let permissionState: String
|
|
24
|
+
|
|
25
|
+
switch CNContactStore.authorizationStatus(for: .contacts) {
|
|
26
|
+
case .notDetermined:
|
|
27
|
+
permissionState = "prompt"
|
|
28
|
+
case .restricted, .denied:
|
|
29
|
+
permissionState = "denied"
|
|
30
|
+
case .authorized:
|
|
31
|
+
permissionState = "granted"
|
|
32
|
+
case .limited:
|
|
33
|
+
permissionState = "limited"
|
|
34
|
+
@unknown default:
|
|
35
|
+
permissionState = "prompt"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
call.resolve([
|
|
39
|
+
"contacts": permissionState
|
|
40
|
+
])
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@objc override public func requestPermissions(_ call: CAPPluginCall) {
|
|
44
|
+
CNContactStore().requestAccess(for: .contacts) { [weak self] _, _ in
|
|
45
|
+
self?.checkPermissions(call)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private func requestContactsPermission(_ call: CAPPluginCall, _ callingMethod: CallingMethod) {
|
|
50
|
+
self.callingMethod = callingMethod
|
|
51
|
+
if isContactsPermissionGranted() {
|
|
52
|
+
permissionCallback(call)
|
|
53
|
+
} else {
|
|
54
|
+
CNContactStore().requestAccess(for: .contacts) { [weak self] _, _ in
|
|
55
|
+
self?.permissionCallback(call)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private func isContactsPermissionGranted() -> Bool {
|
|
61
|
+
switch CNContactStore.authorizationStatus(for: .contacts) {
|
|
62
|
+
case .notDetermined, .restricted, .denied:
|
|
63
|
+
return false
|
|
64
|
+
case .authorized, .limited:
|
|
65
|
+
return true
|
|
66
|
+
@unknown default:
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private func permissionCallback(_ call: CAPPluginCall) {
|
|
72
|
+
let method = self.callingMethod
|
|
73
|
+
|
|
74
|
+
self.callingMethod = nil
|
|
75
|
+
|
|
76
|
+
if !isContactsPermissionGranted() {
|
|
77
|
+
call.reject("Permission is required to access contacts.")
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
switch method {
|
|
82
|
+
case .GetContact:
|
|
83
|
+
getContact(call)
|
|
84
|
+
case .GetContacts:
|
|
85
|
+
getContacts(call)
|
|
86
|
+
case .CreateContact:
|
|
87
|
+
createContact(call)
|
|
88
|
+
case .DeleteContact:
|
|
89
|
+
deleteContact(call)
|
|
90
|
+
case .PickContact:
|
|
91
|
+
pickContact(call)
|
|
92
|
+
default:
|
|
93
|
+
// No method was being called,
|
|
94
|
+
// so nothing has to be done here.
|
|
95
|
+
break
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@objc func getContact(_ call: CAPPluginCall) {
|
|
100
|
+
if !isContactsPermissionGranted() {
|
|
101
|
+
requestContactsPermission(call, CallingMethod.GetContact)
|
|
102
|
+
} else {
|
|
103
|
+
let contactId = call.getString("contactId")
|
|
104
|
+
|
|
105
|
+
guard let contactId = contactId else {
|
|
106
|
+
call.reject("Parameter `contactId` not provided.")
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let projectionInput = GetContactsProjectionInput(call.getObject("projection") ?? JSObject())
|
|
111
|
+
|
|
112
|
+
let contact = implementation.getContact(contactId, projectionInput)
|
|
113
|
+
|
|
114
|
+
guard let contact = contact else {
|
|
115
|
+
call.reject("Contact not found.")
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
call.resolve([
|
|
120
|
+
"contact": contact.getJSObject()
|
|
121
|
+
])
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@objc func getContacts(_ call: CAPPluginCall) {
|
|
126
|
+
if !isContactsPermissionGranted() {
|
|
127
|
+
requestContactsPermission(call, CallingMethod.GetContacts)
|
|
128
|
+
} else {
|
|
129
|
+
let projectionInput = GetContactsProjectionInput(call.getObject("projection") ?? JSObject())
|
|
130
|
+
|
|
131
|
+
let contacts = implementation.getContacts(projectionInput)
|
|
132
|
+
|
|
133
|
+
var contactsJSArray: JSArray = JSArray()
|
|
134
|
+
|
|
135
|
+
for contact in contacts {
|
|
136
|
+
contactsJSArray.append(contact.getJSObject())
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
call.resolve([
|
|
140
|
+
"contacts": contactsJSArray
|
|
141
|
+
])
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@objc func createContact(_ call: CAPPluginCall) {
|
|
146
|
+
if !isContactsPermissionGranted() {
|
|
147
|
+
requestContactsPermission(call, CallingMethod.CreateContact)
|
|
148
|
+
} else {
|
|
149
|
+
let contactInput = CreateContactInput.init(call.getObject("contact", JSObject()))
|
|
150
|
+
|
|
151
|
+
let contactId = implementation.createContact(contactInput)
|
|
152
|
+
|
|
153
|
+
guard let contactId = contactId else {
|
|
154
|
+
call.reject("Something went wrong.")
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
call.resolve([
|
|
159
|
+
"contactId": contactId
|
|
160
|
+
])
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@objc func deleteContact(_ call: CAPPluginCall) {
|
|
165
|
+
if !isContactsPermissionGranted() {
|
|
166
|
+
requestContactsPermission(call, CallingMethod.DeleteContact)
|
|
167
|
+
} else {
|
|
168
|
+
let contactId = call.getString("contactId")
|
|
169
|
+
|
|
170
|
+
guard let contactId = contactId else {
|
|
171
|
+
call.reject("Parameter `contactId` not provided.")
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if !implementation.deleteContact(contactId) {
|
|
176
|
+
call.reject("Something went wrong.")
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
call.resolve()
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@objc func pickContact(_ call: CAPPluginCall) {
|
|
185
|
+
if !isContactsPermissionGranted() {
|
|
186
|
+
requestContactsPermission(call, CallingMethod.PickContact)
|
|
187
|
+
} else {
|
|
188
|
+
DispatchQueue.main.async {
|
|
189
|
+
// Save the call and its callback id
|
|
190
|
+
self.bridge?.saveCall(call)
|
|
191
|
+
self.pickContactCallbackId = call.callbackId
|
|
192
|
+
|
|
193
|
+
// Initialize the contact picker
|
|
194
|
+
let contactPicker = CNContactPickerViewController()
|
|
195
|
+
// Mark current class as the delegate class,
|
|
196
|
+
// this will make the callback `contactPicker` actually work.
|
|
197
|
+
contactPicker.delegate = self
|
|
198
|
+
// Present (open) the native contact picker.
|
|
199
|
+
self.bridge?.viewController?.present(contactPicker, animated: true)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public func contactPicker(_ picker: CNContactPickerViewController, didSelect selectedContact: CNContact) {
|
|
205
|
+
let call = self.bridge?.savedCall(withID: self.pickContactCallbackId ?? "")
|
|
206
|
+
|
|
207
|
+
guard let call = call else {
|
|
208
|
+
return
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
let contact = ContactPayload(selectedContact.identifier)
|
|
212
|
+
|
|
213
|
+
contact.fillData(selectedContact)
|
|
214
|
+
|
|
215
|
+
call.resolve([
|
|
216
|
+
"contact": contact.getJSObject()
|
|
217
|
+
])
|
|
218
|
+
|
|
219
|
+
self.bridge?.releaseCall(call)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
public class CreateContactInput {
|
|
5
|
+
|
|
6
|
+
// Name
|
|
7
|
+
public var nameGiven: String?
|
|
8
|
+
public var nameMiddle: String?
|
|
9
|
+
public var nameFamily: String?
|
|
10
|
+
public var namePrefix: String?
|
|
11
|
+
public var nameSuffix: String?
|
|
12
|
+
|
|
13
|
+
// Organization
|
|
14
|
+
public var organizationName: String?
|
|
15
|
+
public var organizationJobTitle: String?
|
|
16
|
+
public var organizationDepartment: String?
|
|
17
|
+
|
|
18
|
+
// Birthday
|
|
19
|
+
public var birthday: DateComponents?
|
|
20
|
+
|
|
21
|
+
// Note
|
|
22
|
+
public var note: String?
|
|
23
|
+
|
|
24
|
+
// Phones
|
|
25
|
+
public var phones: [PhoneInput] = []
|
|
26
|
+
|
|
27
|
+
// Emails
|
|
28
|
+
public var emails: [EmailInput] = []
|
|
29
|
+
|
|
30
|
+
// URLs
|
|
31
|
+
public var urls: [String] = []
|
|
32
|
+
|
|
33
|
+
// Postal Addresses
|
|
34
|
+
public var postalAddresses: [PostalAddressInput] = []
|
|
35
|
+
|
|
36
|
+
// Image
|
|
37
|
+
public var image: ImageInput?
|
|
38
|
+
|
|
39
|
+
init(_ fromJSONObject: JSObject) {
|
|
40
|
+
// Name
|
|
41
|
+
if let nameObject = fromJSONObject["name"] as? JSObject {
|
|
42
|
+
self.nameGiven = nameObject["given"] as? String
|
|
43
|
+
self.nameMiddle = nameObject["middle"] as? String
|
|
44
|
+
self.nameFamily = nameObject["family"] as? String
|
|
45
|
+
self.namePrefix = nameObject["prefix"] as? String
|
|
46
|
+
self.nameSuffix = nameObject["suffix"] as? String
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Organization
|
|
50
|
+
if let organizationObject = fromJSONObject["organization"] as? JSObject {
|
|
51
|
+
self.organizationName = organizationObject["company"] as? String
|
|
52
|
+
self.organizationJobTitle = organizationObject["jobTitle"] as? String
|
|
53
|
+
self.organizationDepartment = organizationObject["department"] as? String
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Birthday
|
|
57
|
+
if let birthdayObject = fromJSONObject["birthday"] as? JSObject {
|
|
58
|
+
let year = birthdayObject["year"] as? Int
|
|
59
|
+
let month = birthdayObject["month"] as? Int
|
|
60
|
+
let day = birthdayObject["day"] as? Int
|
|
61
|
+
let dateComponents = DateComponents(calendar: .current, timeZone: nil, year: year, month: month, day: day)
|
|
62
|
+
|
|
63
|
+
if dateComponents.isValidDate {
|
|
64
|
+
self.birthday = dateComponents
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Note
|
|
69
|
+
self.note = fromJSONObject["note"] as? String
|
|
70
|
+
|
|
71
|
+
// Phones
|
|
72
|
+
if let phonesArray = fromJSONObject["phones"] as? JSArray {
|
|
73
|
+
for phone in phonesArray {
|
|
74
|
+
if let phoneObject = phone as? JSObject {
|
|
75
|
+
self.phones.append(PhoneInput.init(phoneObject))
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Emails
|
|
81
|
+
if let emailsArray = fromJSONObject["emails"] as? JSArray {
|
|
82
|
+
for email in emailsArray {
|
|
83
|
+
if let emailObject = email as? JSObject {
|
|
84
|
+
self.emails.append(EmailInput.init(emailObject))
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// URLs
|
|
90
|
+
if let urlsArray = fromJSONObject["urls"] as? JSArray {
|
|
91
|
+
for url in urlsArray {
|
|
92
|
+
if let url = url as? String {
|
|
93
|
+
self.urls.append(url)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Postal Addresses
|
|
99
|
+
if let postalAddressesArray = fromJSONObject["postalAddresses"] as? JSArray {
|
|
100
|
+
for postalAddress in postalAddressesArray {
|
|
101
|
+
if let postalAddressObject = postalAddress as? JSObject {
|
|
102
|
+
self.postalAddresses.append(PostalAddressInput.init(postalAddressObject))
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Image
|
|
108
|
+
if let imageObject = fromJSONObject["image"] as? JSObject {
|
|
109
|
+
self.image = ImageInput.init(imageObject)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static func getType(_ type: String?, _ fromJSONObject: JSObject) -> String? {
|
|
114
|
+
// On Android, a custom label is saved with `type` set to "custom" and a separate `label` attribute.
|
|
115
|
+
// On iOS, on the contrary, the custom value is just saved into the `type` attribute.
|
|
116
|
+
|
|
117
|
+
if type == "custom" {
|
|
118
|
+
return fromJSONObject["label"] as? String ?? nil
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return type
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public class PhoneInput {
|
|
125
|
+
|
|
126
|
+
public var type: String?
|
|
127
|
+
|
|
128
|
+
public var number: String?
|
|
129
|
+
|
|
130
|
+
init(_ fromJSONObject: JSObject) {
|
|
131
|
+
let type = Contacts.phoneTypeMap.getValue(fromJSONObject["type"] as? String)
|
|
132
|
+
|
|
133
|
+
self.type = CreateContactInput.getType(type, fromJSONObject)
|
|
134
|
+
|
|
135
|
+
self.number = fromJSONObject["number"] as? String
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public class EmailInput {
|
|
140
|
+
|
|
141
|
+
public var type: String?
|
|
142
|
+
|
|
143
|
+
public var address: String?
|
|
144
|
+
|
|
145
|
+
init(_ fromJSONObject: JSObject) {
|
|
146
|
+
let type = Contacts.emailTypeMap.getValue(fromJSONObject["type"] as? String)
|
|
147
|
+
|
|
148
|
+
self.type = CreateContactInput.getType(type, fromJSONObject)
|
|
149
|
+
|
|
150
|
+
self.address = fromJSONObject["address"] as? String
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public class PostalAddressInput {
|
|
155
|
+
|
|
156
|
+
public var type: String?
|
|
157
|
+
|
|
158
|
+
public var street: String?
|
|
159
|
+
public var neighborhood: String?
|
|
160
|
+
public var city: String?
|
|
161
|
+
public var region: String?
|
|
162
|
+
public var postcode: String?
|
|
163
|
+
public var country: String?
|
|
164
|
+
|
|
165
|
+
init(_ fromJSONObject: JSObject) {
|
|
166
|
+
let type = Contacts.postalAddressTypeMap.getValue(fromJSONObject["type"] as? String)
|
|
167
|
+
|
|
168
|
+
self.type = CreateContactInput.getType(type, fromJSONObject)
|
|
169
|
+
|
|
170
|
+
self.street = fromJSONObject["street"] as? String
|
|
171
|
+
self.neighborhood = fromJSONObject["neighborhood"] as? String
|
|
172
|
+
self.city = fromJSONObject["city"] as? String
|
|
173
|
+
self.region = fromJSONObject["region"] as? String
|
|
174
|
+
self.postcode = fromJSONObject["postcode"] as? String
|
|
175
|
+
self.country = fromJSONObject["country"] as? String
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public class ImageInput {
|
|
180
|
+
|
|
181
|
+
public var base64String: String?
|
|
182
|
+
|
|
183
|
+
init(_ fromJSONObject: JSObject) {
|
|
184
|
+
self.base64String = fromJSONObject["base64String"] as? String
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import Contacts
|
|
4
|
+
|
|
5
|
+
public class GetContactsProjectionInput {
|
|
6
|
+
// Name
|
|
7
|
+
private var name: Bool?
|
|
8
|
+
|
|
9
|
+
// Organization
|
|
10
|
+
private var organization: Bool?
|
|
11
|
+
|
|
12
|
+
// Birthday
|
|
13
|
+
private var birthday: Bool?
|
|
14
|
+
|
|
15
|
+
// Note
|
|
16
|
+
private var note: Bool?
|
|
17
|
+
|
|
18
|
+
// Phones
|
|
19
|
+
private var phones: Bool?
|
|
20
|
+
|
|
21
|
+
// Emails
|
|
22
|
+
private var emails: Bool?
|
|
23
|
+
|
|
24
|
+
// URLs
|
|
25
|
+
private var urls: Bool?
|
|
26
|
+
|
|
27
|
+
// Postal Addresses
|
|
28
|
+
private var postalAddresses: Bool?
|
|
29
|
+
|
|
30
|
+
// Image
|
|
31
|
+
private var image: Bool?
|
|
32
|
+
|
|
33
|
+
init(_ fromJSONObject: JSObject) {
|
|
34
|
+
// Name
|
|
35
|
+
self.name = fromJSONObject["name"] as? Bool
|
|
36
|
+
|
|
37
|
+
// Organization
|
|
38
|
+
self.organization = fromJSONObject["organization"] as? Bool
|
|
39
|
+
|
|
40
|
+
// Birthday
|
|
41
|
+
self.birthday = fromJSONObject["birthday"] as? Bool
|
|
42
|
+
|
|
43
|
+
// Note
|
|
44
|
+
self.note = fromJSONObject["note"] as? Bool
|
|
45
|
+
|
|
46
|
+
// Phones
|
|
47
|
+
self.phones = fromJSONObject["phones"] as? Bool
|
|
48
|
+
|
|
49
|
+
// Emails
|
|
50
|
+
self.emails = fromJSONObject["emails"] as? Bool
|
|
51
|
+
|
|
52
|
+
// URLs
|
|
53
|
+
self.urls = fromJSONObject["urls"] as? Bool
|
|
54
|
+
|
|
55
|
+
// Postal Addresses
|
|
56
|
+
self.postalAddresses = fromJSONObject["postalAddresses"] as? Bool
|
|
57
|
+
|
|
58
|
+
// Image
|
|
59
|
+
self.image = fromJSONObject["image"] as? Bool
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public func getProjection() -> [CNKeyDescriptor] {
|
|
63
|
+
var projection: [CNKeyDescriptor] = []
|
|
64
|
+
|
|
65
|
+
// Name
|
|
66
|
+
if self.name == true {
|
|
67
|
+
projection.append(CNContactFormatter.descriptorForRequiredKeys(for: .fullName))
|
|
68
|
+
projection.append(CNContactGivenNameKey as CNKeyDescriptor)
|
|
69
|
+
projection.append(CNContactMiddleNameKey as CNKeyDescriptor)
|
|
70
|
+
projection.append(CNContactFamilyNameKey as CNKeyDescriptor)
|
|
71
|
+
projection.append(CNContactNamePrefixKey as CNKeyDescriptor)
|
|
72
|
+
projection.append(CNContactNameSuffixKey as CNKeyDescriptor)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Organization
|
|
76
|
+
if self.organization == true {
|
|
77
|
+
projection.append(CNContactOrganizationNameKey as CNKeyDescriptor)
|
|
78
|
+
projection.append(CNContactJobTitleKey as CNKeyDescriptor)
|
|
79
|
+
projection.append(CNContactDepartmentNameKey as CNKeyDescriptor)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Birthday
|
|
83
|
+
if self.birthday == true {
|
|
84
|
+
projection.append(CNContactBirthdayKey as CNKeyDescriptor)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Note
|
|
88
|
+
if self.note == true {
|
|
89
|
+
projection.append(CNContactNoteKey as CNKeyDescriptor)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Phones
|
|
93
|
+
if self.phones == true {
|
|
94
|
+
projection.append(CNContactPhoneNumbersKey as CNKeyDescriptor)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Emails
|
|
98
|
+
if self.emails == true {
|
|
99
|
+
projection.append(CNContactEmailAddressesKey as CNKeyDescriptor)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// URLs
|
|
103
|
+
if self.urls == true {
|
|
104
|
+
projection.append(CNContactUrlAddressesKey as CNKeyDescriptor)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Postal Addresses
|
|
108
|
+
if self.postalAddresses == true {
|
|
109
|
+
projection.append(CNContactPostalAddressesKey as CNKeyDescriptor)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Image
|
|
113
|
+
if self.image == true {
|
|
114
|
+
projection.append(CNContactImageDataKey as CNKeyDescriptor)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return projection
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleExecutable</key>
|
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
+
<key>CFBundleIdentifier</key>
|
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
+
<string>6.0</string>
|
|
13
|
+
<key>CFBundleName</key>
|
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
|
15
|
+
<key>CFBundlePackageType</key>
|
|
16
|
+
<string>FMWK</string>
|
|
17
|
+
<key>CFBundleShortVersionString</key>
|
|
18
|
+
<string>1.0</string>
|
|
19
|
+
<key>CFBundleVersion</key>
|
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSPrincipalClass</key>
|
|
22
|
+
<string></string>
|
|
23
|
+
</dict>
|
|
24
|
+
</plist>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aalzehla/capacitor-contacts",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
|
+
"description": "Contacts Plugin for Capacitor",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/esm/index.d.ts",
|
|
@@ -10,59 +10,62 @@
|
|
|
10
10
|
"android/src/main/",
|
|
11
11
|
"android/build.gradle",
|
|
12
12
|
"dist/",
|
|
13
|
-
"ios/
|
|
14
|
-
"ios/Tests",
|
|
15
|
-
"Package.swift",
|
|
13
|
+
"ios/Plugin/",
|
|
16
14
|
"AalzehlaCapacitorContacts.podspec"
|
|
17
15
|
],
|
|
18
|
-
"author": "
|
|
16
|
+
"author": "",
|
|
19
17
|
"license": "MIT",
|
|
20
18
|
"repository": {
|
|
21
19
|
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/
|
|
20
|
+
"url": "git+https://github.com/capacitor-community/contacts.git"
|
|
23
21
|
},
|
|
24
22
|
"bugs": {
|
|
25
|
-
"url": "https://github.com/
|
|
23
|
+
"url": "https://github.com/capacitor-community/contacts/issues"
|
|
26
24
|
},
|
|
27
25
|
"keywords": [
|
|
28
26
|
"capacitor",
|
|
29
|
-
"plugin"
|
|
30
|
-
"native"
|
|
27
|
+
"plugin"
|
|
31
28
|
],
|
|
32
29
|
"scripts": {
|
|
33
30
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
34
|
-
"verify:ios": "xcodebuild -scheme
|
|
31
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
|
35
32
|
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
36
33
|
"verify:web": "npm run build",
|
|
37
34
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
38
35
|
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
39
36
|
"eslint": "eslint . --ext ts",
|
|
40
|
-
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
37
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java --write",
|
|
41
38
|
"swiftlint": "node-swiftlint",
|
|
42
|
-
"docgen": "docgen --api
|
|
43
|
-
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.
|
|
39
|
+
"docgen": "docgen --api ContactsPlugin --output-readme ./docs/api.md",
|
|
40
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
44
41
|
"clean": "rimraf ./dist",
|
|
45
42
|
"watch": "tsc --watch",
|
|
46
|
-
"prepublishOnly": "npm run build"
|
|
43
|
+
"prepublishOnly": "npm run build",
|
|
44
|
+
"release": "standard-version"
|
|
47
45
|
},
|
|
48
46
|
"devDependencies": {
|
|
49
|
-
"@capacitor/android": "^
|
|
50
|
-
"@capacitor/core": "^
|
|
51
|
-
"@capacitor/
|
|
52
|
-
"@
|
|
47
|
+
"@capacitor/android": "^8.0.0",
|
|
48
|
+
"@capacitor/core": "^8.0.0",
|
|
49
|
+
"@capacitor/ios": "^8.0.0",
|
|
50
|
+
"@commitlint/cli": "^17.3.0",
|
|
51
|
+
"@commitlint/config-conventional": "^17.3.0",
|
|
53
52
|
"@ionic/eslint-config": "^0.4.0",
|
|
54
|
-
"@ionic/prettier-config": "^
|
|
55
|
-
"@ionic/swiftlint-config": "^
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
53
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
54
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
55
|
+
"@tafelnl/capacitor-docgen": "^0.1.1",
|
|
56
|
+
"@types/node": "^24.10.1",
|
|
57
|
+
"eslint": "^8.57.1",
|
|
58
|
+
"husky": "^8.0.2",
|
|
59
|
+
"prettier": "^3.6.2",
|
|
60
|
+
"prettier-plugin-java": "^2.7.7",
|
|
61
|
+
"rimraf": "^6.1.0",
|
|
62
|
+
"rollup": "^4.53.2",
|
|
63
|
+
"standard-version": "^9.5.0",
|
|
64
|
+
"swiftlint": "^2.0.0",
|
|
65
|
+
"typescript": "^5.9.3"
|
|
63
66
|
},
|
|
64
67
|
"peerDependencies": {
|
|
65
|
-
"@capacitor/core": "
|
|
68
|
+
"@capacitor/core": ">=8.0.0"
|
|
66
69
|
},
|
|
67
70
|
"prettier": "@ionic/prettier-config",
|
|
68
71
|
"swiftlint": "@ionic/swiftlint-config",
|
package/Package.swift
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// swift-tools-version: 5.9
|
|
2
|
-
import PackageDescription
|
|
3
|
-
|
|
4
|
-
let package = Package(
|
|
5
|
-
name: "CapacitorContacts",
|
|
6
|
-
platforms: [.iOS(.v13)],
|
|
7
|
-
products: [
|
|
8
|
-
.library(
|
|
9
|
-
name: "CapacitorContacts",
|
|
10
|
-
targets: ["CapacitorContactsPlugin"])
|
|
11
|
-
],
|
|
12
|
-
dependencies: [
|
|
13
|
-
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch: "main")
|
|
14
|
-
],
|
|
15
|
-
targets: [
|
|
16
|
-
.target(
|
|
17
|
-
name: "CapacitorContactsPlugin",
|
|
18
|
-
dependencies: [
|
|
19
|
-
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
-
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
-
],
|
|
22
|
-
path: "ios/Sources/CapacitorContactsPlugin"),
|
|
23
|
-
.testTarget(
|
|
24
|
-
name: "CapacitorContactsPluginTests",
|
|
25
|
-
dependencies: ["CapacitorContactsPlugin"],
|
|
26
|
-
path: "ios/Tests/CapacitorContactsPluginTests")
|
|
27
|
-
]
|
|
28
|
-
)
|