@hanwha-ss1/plugin 0.0.1 → 0.0.2
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 +12 -8
- package/ios/Plugin/ContactPlugin.swift +54 -34
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
OpenBrowser
|
|
4
|
-
|
|
1
|
+
# @hanwha-ss1/plugin
|
|
5
2
|
## Install
|
|
6
3
|
|
|
7
4
|
```bash
|
|
8
|
-
npm install
|
|
5
|
+
npm install @hanwha-ss1/plugin
|
|
9
6
|
npx cap sync
|
|
10
7
|
```
|
|
11
8
|
|
|
12
9
|
## Example
|
|
13
10
|
|
|
14
11
|
```javascript
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
import { HanwhaPlugin } from "@hanwha-ss1/plugin"
|
|
13
|
+
|
|
14
|
+
// 연락처 저장
|
|
15
|
+
await HanwhaPlugin.addContact({
|
|
16
|
+
name: "이름님",
|
|
17
|
+
phone: "010-2222-3333",
|
|
18
|
+
email: "이메일",
|
|
19
|
+
dept: "회사",
|
|
20
|
+
ext: "내선"
|
|
21
|
+
})
|
|
18
22
|
```
|
|
19
23
|
|
|
20
24
|
## API
|
|
@@ -14,63 +14,77 @@ public class Plugin: CAPPlugin {
|
|
|
14
14
|
let phone = call.getString("phone") ?? ""
|
|
15
15
|
let email = call.getString("email") ?? ""
|
|
16
16
|
let dept = call.getString("dept") ?? ""
|
|
17
|
+
let ext = call.getString("ext") ?? ""
|
|
17
18
|
|
|
18
|
-
saveContact(name: name, phone: phone)
|
|
19
|
+
saveContact(name: name, phone: phone, email: email, dept: dept, ext: ext) { success in
|
|
20
|
+
if success {
|
|
21
|
+
call.resolve([
|
|
22
|
+
"result": true,
|
|
23
|
+
"message": "완료"
|
|
24
|
+
])
|
|
25
|
+
} else {
|
|
26
|
+
call.resolve([
|
|
27
|
+
"result": false,
|
|
28
|
+
"message": "존재하는 번호입니다."
|
|
29
|
+
])
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
19
33
|
|
|
20
|
-
call.resolve([
|
|
21
|
-
"results": "완료"
|
|
22
|
-
])
|
|
23
|
-
|
|
24
34
|
}
|
|
25
35
|
|
|
26
|
-
private func saveContact(name: String, phone: String) {
|
|
36
|
+
private func saveContact(name: String, phone: String, email: String, dept: String, ext: String, completion: @escaping (Bool) -> Void) {
|
|
27
37
|
|
|
28
38
|
let store = CNContactStore()
|
|
29
39
|
|
|
30
40
|
// Permission 획득
|
|
31
41
|
store.requestAccess(for: .contacts) { (granted, error) in
|
|
32
42
|
guard granted else {
|
|
43
|
+
completion(false)
|
|
33
44
|
return
|
|
34
45
|
}
|
|
35
46
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let contact: CNMutableContact = self.getNewContact(name, phone)
|
|
47
|
+
if self.getContactsMatchingPhoneNumber(phone) {
|
|
48
|
+
|
|
49
|
+
let contact: CNMutableContact = self.getNewContact(name, phone, email, dept, ext)
|
|
40
50
|
|
|
41
51
|
let request = CNSaveRequest()
|
|
42
52
|
request.add(contact, toContainerWithIdentifier: nil)
|
|
43
53
|
|
|
44
|
-
// 저장
|
|
45
54
|
do {
|
|
46
55
|
try store.execute(request)
|
|
56
|
+
completion(true)
|
|
47
57
|
} catch {
|
|
48
|
-
|
|
58
|
+
|
|
59
|
+
completion(false)
|
|
49
60
|
}
|
|
61
|
+
} else {
|
|
62
|
+
completion(false)
|
|
50
63
|
}
|
|
51
|
-
|
|
52
64
|
}
|
|
53
65
|
}
|
|
54
66
|
// 새로 등록할 주소록 생성
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return contact
|
|
70
|
-
}
|
|
67
|
+
private func getNewContact(_ m_name: String, _ m_phone: String, _ m_email: String, _ m_dept: String, _ m_ext: String) -> CNMutableContact {
|
|
68
|
+
let contact = CNMutableContact()
|
|
69
|
+
contact.givenName = m_name
|
|
70
|
+
|
|
71
|
+
let phone = CNLabeledValue(label:CNLabelPhoneNumberMobile,
|
|
72
|
+
value:CNPhoneNumber(stringValue:m_phone))
|
|
73
|
+
let workLabel = "직장"
|
|
74
|
+
let tel = CNLabeledValue(label:workLabel,
|
|
75
|
+
value:CNPhoneNumber(stringValue:m_ext))
|
|
76
|
+
contact.phoneNumbers = [phone, tel]
|
|
77
|
+
|
|
78
|
+
contact.emailAddresses = [CNLabeledValue(label:CNLabelWork, value:m_email as NSString)]
|
|
79
|
+
contact.organizationName = m_dept
|
|
71
80
|
|
|
72
|
-
|
|
73
|
-
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
return contact
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func getContactsMatchingPhoneNumber(_ phone: String) -> Bool {
|
|
87
|
+
var result = true
|
|
74
88
|
|
|
75
89
|
let store = CNContactStore()
|
|
76
90
|
let keysToFetch: [CNKeyDescriptor] = [CNContactGivenNameKey as CNKeyDescriptor, CNContactFamilyNameKey as CNKeyDescriptor, CNContactPhoneNumbersKey as CNKeyDescriptor]
|
|
@@ -79,12 +93,18 @@ public class Plugin: CAPPlugin {
|
|
|
79
93
|
do {
|
|
80
94
|
let fetchRequest = CNContactFetchRequest(keysToFetch: keysToFetch)
|
|
81
95
|
try store.enumerateContacts(with: fetchRequest) { contact, _ in
|
|
82
|
-
|
|
96
|
+
|
|
83
97
|
for phoneNumber in contact.phoneNumbers {
|
|
98
|
+
|
|
99
|
+
|
|
84
100
|
let label = phoneNumber.label ?? "Phone"
|
|
85
101
|
let value = phoneNumber.value.stringValue
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
|
|
103
|
+
if value == phone {
|
|
104
|
+
print("Name: \(contact.givenName) \(contact.familyName)")
|
|
105
|
+
print("\(label): \(value )")
|
|
106
|
+
result = false
|
|
107
|
+
}
|
|
88
108
|
}
|
|
89
109
|
}
|
|
90
110
|
} catch {
|