@aalzehla/capacitor-contacts 0.0.4 → 8.0.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/{AalzehlaCapacitorContacts.podspec → CapacitorCommunityContacts.podspec} +3 -3
- 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 +33 -30
- 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 -166
- package/ios/Tests/CapacitorContactsPluginTests/CapacitorContactsPluginTests.swift +0 -15
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Capacitor
|
|
3
|
-
import ContactsUI
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Please read the Capacitor iOS Plugin Development Guide
|
|
7
|
-
* here: https://capacitorjs.com/docs/plugins/ios
|
|
8
|
-
*/
|
|
9
|
-
@objc(CapacitorContactsPlugin)
|
|
10
|
-
public class CapacitorContactsPlugin: CAPPlugin, CAPBridgedPlugin, CNContactPickerDelegate {
|
|
11
|
-
public let identifier = "CapacitorContactsPlugin"
|
|
12
|
-
public let jsName = "CapacitorContacts"
|
|
13
|
-
public let pluginMethods: [CAPPluginMethod] = [
|
|
14
|
-
CAPPluginMethod(name: "open", returnType: CAPPluginReturnPromise),
|
|
15
|
-
CAPPluginMethod(name: "close", returnType: CAPPluginReturnPromise)
|
|
16
|
-
]
|
|
17
|
-
|
|
18
|
-
var vc: CNContactPickerViewController?
|
|
19
|
-
var id: String?
|
|
20
|
-
|
|
21
|
-
@objc func open(_ call: CAPPluginCall) {
|
|
22
|
-
self.id = call.callbackId
|
|
23
|
-
call.keepAlive = true
|
|
24
|
-
Permissions.contactPermission { granted in
|
|
25
|
-
if granted {
|
|
26
|
-
DispatchQueue.main.async {
|
|
27
|
-
self.vc = CNContactPickerViewController()
|
|
28
|
-
self.vc!.delegate = self
|
|
29
|
-
self.bridge?.viewController?.present(self.vc!, animated: true, completion: nil)
|
|
30
|
-
}
|
|
31
|
-
} else {
|
|
32
|
-
call.reject("User denied access to contacts")
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@objc func close(_ call: CAPPluginCall) {
|
|
38
|
-
if vc == nil {
|
|
39
|
-
call.resolve()
|
|
40
|
-
}
|
|
41
|
-
DispatchQueue.main.async {
|
|
42
|
-
self.bridge?.dismissVC(animated: true) {
|
|
43
|
-
call.resolve()
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
func makeContact(_ contact: CNContact) -> Dictionary<String, Any> {
|
|
49
|
-
var res: [String:Any] = [:]
|
|
50
|
-
res["contactId"] = contact.identifier;
|
|
51
|
-
res["givenName"] = contact.givenName;
|
|
52
|
-
res["familyName"] = contact.familyName;
|
|
53
|
-
res["nickname"] = contact.nickname;
|
|
54
|
-
res["displayName"] = contact.givenName + " " + contact.familyName;
|
|
55
|
-
res["jobTitle"] = contact.jobTitle;
|
|
56
|
-
res["departmentName"] = contact.departmentName;
|
|
57
|
-
res["organizationName"] = contact.organizationName;
|
|
58
|
-
res["note"] = contact.note;
|
|
59
|
-
|
|
60
|
-
// process email addresses
|
|
61
|
-
var array: [JSObject] = [];
|
|
62
|
-
for emailAddress in contact.emailAddresses {
|
|
63
|
-
var object = JSObject()
|
|
64
|
-
object["type"] = CNLabeledValue<NSString>.localizedString(forLabel: emailAddress.label ?? "")
|
|
65
|
-
if emailAddress.value != "" {
|
|
66
|
-
object["emailAddress"] = emailAddress.value as String
|
|
67
|
-
}
|
|
68
|
-
array.append(object)
|
|
69
|
-
}
|
|
70
|
-
res["emailAddresses"] = array
|
|
71
|
-
|
|
72
|
-
// process phone numbers
|
|
73
|
-
array = [];
|
|
74
|
-
for phoneNumber in contact.phoneNumbers {
|
|
75
|
-
var object = JSObject()
|
|
76
|
-
object["type"] = CNLabeledValue<NSString>.localizedString(forLabel: phoneNumber.label ?? "")
|
|
77
|
-
if phoneNumber.value.stringValue != "" {
|
|
78
|
-
object["phoneNumber"] = phoneNumber.value.stringValue
|
|
79
|
-
}
|
|
80
|
-
array.append(object)
|
|
81
|
-
}
|
|
82
|
-
res["phoneNumbers"] = array
|
|
83
|
-
|
|
84
|
-
// process postal addresses
|
|
85
|
-
array = [];
|
|
86
|
-
for address in contact.postalAddresses {
|
|
87
|
-
var object = JSObject()
|
|
88
|
-
object["formattedAddress"] = CNPostalAddressFormatter().string(from: address.value)
|
|
89
|
-
object["type"] = CNLabeledValue<NSString>.localizedString(forLabel: address.label ?? "")
|
|
90
|
-
if address.value.street != "" {
|
|
91
|
-
object["street"] = address.value.street
|
|
92
|
-
}
|
|
93
|
-
if address.value.city != "" {
|
|
94
|
-
object["city"] = address.value.city
|
|
95
|
-
}
|
|
96
|
-
if address.value.state != "" {
|
|
97
|
-
object["state"] = address.value.state
|
|
98
|
-
}
|
|
99
|
-
if address.value.postalCode != "" {
|
|
100
|
-
object["postalCode"] = address.value.postalCode
|
|
101
|
-
}
|
|
102
|
-
if address.value.country != "" {
|
|
103
|
-
object["country"] = address.value.country
|
|
104
|
-
}
|
|
105
|
-
if address.value.isoCountryCode != "" {
|
|
106
|
-
object["isoCountryCode"] = address.value.isoCountryCode
|
|
107
|
-
}
|
|
108
|
-
if address.value.subAdministrativeArea != "" {
|
|
109
|
-
object["subAdministrativeArea"] = address.value.subAdministrativeArea
|
|
110
|
-
}
|
|
111
|
-
if address.value.subLocality != "" {
|
|
112
|
-
object["subLocality"] = address.value.subLocality
|
|
113
|
-
}
|
|
114
|
-
array.append(object)
|
|
115
|
-
}
|
|
116
|
-
res["postalAddresses"] = array
|
|
117
|
-
|
|
118
|
-
// temporarily disable returning contact imageData because base64 data overwhelms console log
|
|
119
|
-
/*if contact.imageData != nil {
|
|
120
|
-
let image = UIImage(data: contact.imageData!)?.pngData() ?? UIImage(data: contact.imageData!)?.jpegData(compressionQuality: 0);
|
|
121
|
-
res["image"] = image!.base64EncodedString(options: .lineLength64Characters);
|
|
122
|
-
}*/
|
|
123
|
-
|
|
124
|
-
return res
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// didSelect contacts: [CNContact]
|
|
128
|
-
public func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
|
|
129
|
-
picker.dismiss(animated: true, completion: nil)
|
|
130
|
-
guard let call = self.bridge?.savedCall(withID: self.id!) else {
|
|
131
|
-
print("call was not loaded correctly")
|
|
132
|
-
return
|
|
133
|
-
}
|
|
134
|
-
//print("result: " + String(describing: contact))
|
|
135
|
-
call.resolve(makeContact(contact));
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
public func contactPickerDidCancel(_ picker: CNContactPickerViewController) {
|
|
139
|
-
//print("closed!")
|
|
140
|
-
picker.dismiss(animated: true, completion: nil)
|
|
141
|
-
guard let call = self.bridge?.savedCall(withID: self.id!) else { return }
|
|
142
|
-
call.resolve()
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
class Permissions {
|
|
147
|
-
class func contactPermission(completionHandler: @escaping (_ accessGranted: Bool) -> Void) {
|
|
148
|
-
let contactStore = CNContactStore()
|
|
149
|
-
switch CNContactStore.authorizationStatus(for: .contacts) {
|
|
150
|
-
case .authorized:
|
|
151
|
-
completionHandler(true)
|
|
152
|
-
case .denied:
|
|
153
|
-
completionHandler(false)
|
|
154
|
-
case .restricted, .notDetermined:
|
|
155
|
-
contactStore.requestAccess(for: .contacts) { granted, _ in
|
|
156
|
-
if granted {
|
|
157
|
-
completionHandler(true)
|
|
158
|
-
} else {
|
|
159
|
-
DispatchQueue.main.async {
|
|
160
|
-
completionHandler(false)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import XCTest
|
|
2
|
-
@testable import CapacitorContactsPlugin
|
|
3
|
-
|
|
4
|
-
class CapacitorContactsTests: XCTestCase {
|
|
5
|
-
func testEcho() {
|
|
6
|
-
// This is an example of a functional test case for a plugin.
|
|
7
|
-
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
-
|
|
9
|
-
let implementation = CapacitorContacts()
|
|
10
|
-
let value = "Hello, World!"
|
|
11
|
-
let result = implementation.echo(value)
|
|
12
|
-
|
|
13
|
-
XCTAssertEqual(value, result)
|
|
14
|
-
}
|
|
15
|
-
}
|