@hanwha-ss1/plugin 0.0.4 → 0.0.6
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
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
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
|
+
})
|
|
22
|
+
|
|
23
|
+
// 스크린샷 방지
|
|
24
|
+
await HanwhaPlugin.setScreenCaptureDisabled({
|
|
25
|
+
disabled: "true"
|
|
26
|
+
})
|
|
18
27
|
```
|
|
19
28
|
|
|
20
29
|
## API
|
|
@@ -14,93 +14,131 @@ 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) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
private func saveContact(name: String, phone: String, email: String, dept: String, ext: String, completion: @escaping (Bool) -> Void) {
|
|
37
|
+
|
|
38
|
+
let store = CNContactStore()
|
|
39
|
+
|
|
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
|
-
|
|
36
|
-
// 전화번호 중복 여부 확인
|
|
37
|
-
self.getContactsMatchingPhoneNumber(phone)
|
|
38
|
-
// if let existingContact = self.getContactWithPhoneNumber(phone) {
|
|
39
|
-
// // 이미 해당 전화번호를 가진 연락처가 있음
|
|
40
|
-
// // 여기서 원하는 작업을 수행하거나 오류 처리를 할 수 있음
|
|
41
|
-
// } else {
|
|
42
|
-
// // 해당 전화번호를 가진 연락처가 없음
|
|
43
|
-
// let contact: CNMutableContact = self.getNewContact(name, phone)
|
|
44
|
-
//
|
|
45
|
-
// let request = CNSaveRequest()
|
|
46
|
-
// request.add(contact, toContainerWithIdentifier: nil)
|
|
47
|
-
//
|
|
48
|
-
// // 저장
|
|
49
|
-
// do {
|
|
50
|
-
// try store.execute(request)
|
|
51
|
-
// } catch {
|
|
52
|
-
// // 저장 중 오류 처리
|
|
53
|
-
// }
|
|
54
|
-
// }
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 새로 등록할 주소록 생성
|
|
59
|
-
private func getNewContact(_ m_name: String, _ m_phone: String) -> CNMutableContact {
|
|
60
|
-
let contact = CNMutableContact()
|
|
61
|
-
contact.givenName = m_name
|
|
62
|
-
// contact.familyName = "familyName"
|
|
63
|
-
|
|
64
|
-
let phone = CNLabeledValue(label:CNLabelPhoneNumberMobile,
|
|
65
|
-
value:CNPhoneNumber(stringValue:m_phone))
|
|
66
|
-
let tel = CNLabeledValue(label:CNLabelPhoneNumberMain,
|
|
67
|
-
value:CNPhoneNumber(stringValue:m_phone))
|
|
68
|
-
contact.phoneNumbers = [phone, tel]
|
|
69
46
|
|
|
70
|
-
|
|
71
|
-
contact.emailAddresses = [CNLabeledValue(label:CNLabelWork, value:email)]
|
|
47
|
+
if self.getContactsMatchingPhoneNumber(phone) {
|
|
72
48
|
|
|
73
|
-
|
|
49
|
+
let contact: CNMutableContact = self.getNewContact(name, phone, email, dept, ext)
|
|
50
|
+
|
|
51
|
+
let request = CNSaveRequest()
|
|
52
|
+
request.add(contact, toContainerWithIdentifier: nil)
|
|
53
|
+
|
|
54
|
+
do {
|
|
55
|
+
try store.execute(request)
|
|
56
|
+
completion(true)
|
|
57
|
+
} catch {
|
|
58
|
+
|
|
59
|
+
completion(false)
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
completion(false)
|
|
63
|
+
}
|
|
74
64
|
}
|
|
65
|
+
}
|
|
66
|
+
// 새로 등록할 주소록 생성
|
|
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
|
|
75
80
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
return contact
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func getContactsMatchingPhoneNumber(_ phone: String) -> Bool {
|
|
87
|
+
var result = true
|
|
88
|
+
|
|
79
89
|
let store = CNContactStore()
|
|
80
90
|
let keysToFetch: [CNKeyDescriptor] = [CNContactGivenNameKey as CNKeyDescriptor, CNContactFamilyNameKey as CNKeyDescriptor, CNContactPhoneNumbersKey as CNKeyDescriptor]
|
|
81
|
-
|
|
82
|
-
// 전화번호에 일치하는 연락처를 검색하기 위한 NSPredicate를 생성
|
|
83
|
-
let predicate = CNContact.predicateForContacts(withIdentifiers: [])
|
|
84
|
-
|
|
85
|
-
do {
|
|
86
|
-
// 모든 연락처 가져오기
|
|
87
|
-
let allContacts = try store.unifiedContacts(matching: predicate, keysToFetch: keysToFetch)
|
|
91
|
+
|
|
88
92
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
do {
|
|
94
|
+
let fetchRequest = CNContactFetchRequest(keysToFetch: keysToFetch)
|
|
95
|
+
try store.enumerateContacts(with: fetchRequest) { contact, _ in
|
|
96
|
+
|
|
97
|
+
for phoneNumber in contact.phoneNumbers {
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
let label = phoneNumber.label ?? "Phone"
|
|
101
|
+
let value = phoneNumber.value.stringValue
|
|
102
|
+
|
|
103
|
+
if value == phone {
|
|
104
|
+
print("Name: \(contact.givenName) \(contact.familyName)")
|
|
105
|
+
print("\(label): \(value )")
|
|
106
|
+
result = false
|
|
96
107
|
}
|
|
97
108
|
}
|
|
98
109
|
}
|
|
99
110
|
} catch {
|
|
100
|
-
|
|
111
|
+
print("Error fetching contacts: \(error)")
|
|
101
112
|
}
|
|
102
|
-
|
|
103
|
-
return
|
|
113
|
+
|
|
114
|
+
return result
|
|
104
115
|
}
|
|
116
|
+
//
|
|
117
|
+
// let store = CNContactStore()
|
|
118
|
+
// let keysToFetch: [CNKeyDescriptor] = [CNContactGivenNameKey as CNKeyDescriptor, CNContactFamilyNameKey as CNKeyDescriptor, CNContactPhoneNumbersKey as CNKeyDescriptor]
|
|
119
|
+
//
|
|
120
|
+
// // 전화번호에 일치하는 연락처를 검색하기 위한 NSPredicate를 생성
|
|
121
|
+
// let predicate = CNContact.predicateForContacts(withIdentifiers: [phoneNumber])
|
|
122
|
+
//
|
|
123
|
+
// do {
|
|
124
|
+
// // 모든 연락처 가져오기
|
|
125
|
+
// let allContacts = try store.unifiedContacts(matching: predicate, keysToFetch: keysToFetch)
|
|
126
|
+
//
|
|
127
|
+
// // 전화번호와 일치하는 연락처를 선택
|
|
128
|
+
// for contact in allContacts {
|
|
129
|
+
// for phoneNumberValue in contact.phoneNumbers {
|
|
130
|
+
// let number = phoneNumberValue.value
|
|
131
|
+
// if number.stringValue.contains(phoneNumber) {
|
|
132
|
+
// matchingContacts.append(contact)
|
|
133
|
+
// break
|
|
134
|
+
// }
|
|
135
|
+
// }
|
|
136
|
+
// }
|
|
137
|
+
// } catch {
|
|
138
|
+
// // 검색 중 오류 처리
|
|
139
|
+
// }
|
|
140
|
+
//
|
|
141
|
+
// return matchingContacts
|
|
142
|
+
// }
|
|
105
143
|
}
|
|
106
144
|
|