@hanwha-ss1/plugin 0.1.2 → 0.1.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.
package/ios/Plugin/Contact.swift
CHANGED
|
@@ -1,10 +1,87 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import UIKit
|
|
3
|
-
|
|
3
|
+
import Contacts
|
|
4
4
|
|
|
5
5
|
@objc public class Contact: NSObject {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
|
|
7
|
+
@objc public func saveContact(name: String, phone: String, email: String, dept: String, ext: String, completion: @escaping (Bool) -> Void) {
|
|
8
|
+
|
|
9
|
+
let store = CNContactStore()
|
|
10
|
+
|
|
11
|
+
// Permission 획득
|
|
12
|
+
store.requestAccess(for: .contacts) { (granted, error) in
|
|
13
|
+
guard granted else {
|
|
14
|
+
completion(false)
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if self.getContactsMatchingPhoneNumber(phone) {
|
|
19
|
+
|
|
20
|
+
let contact: CNMutableContact = self.getNewContact(name, phone, email, dept, ext)
|
|
21
|
+
|
|
22
|
+
let request = CNSaveRequest()
|
|
23
|
+
request.add(contact, toContainerWithIdentifier: nil)
|
|
24
|
+
|
|
25
|
+
do {
|
|
26
|
+
try store.execute(request)
|
|
27
|
+
completion(true)
|
|
28
|
+
} catch {
|
|
29
|
+
|
|
30
|
+
completion(false)
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
completion(false)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// 새로 등록할 주소록 생성
|
|
38
|
+
private func getNewContact(_ m_name: String, _ m_phone: String, _ m_email: String, _ m_dept: String, _ m_ext: String) -> CNMutableContact {
|
|
39
|
+
let contact = CNMutableContact()
|
|
40
|
+
contact.givenName = m_name
|
|
41
|
+
|
|
42
|
+
let phone = CNLabeledValue(label:CNLabelPhoneNumberMobile,
|
|
43
|
+
value:CNPhoneNumber(stringValue:m_phone))
|
|
44
|
+
let workLabel = "직장"
|
|
45
|
+
let tel = CNLabeledValue(label:workLabel,
|
|
46
|
+
value:CNPhoneNumber(stringValue:m_ext))
|
|
47
|
+
contact.phoneNumbers = [phone, tel]
|
|
48
|
+
|
|
49
|
+
contact.emailAddresses = [CNLabeledValue(label:CNLabelWork, value:m_email as NSString)]
|
|
50
|
+
contact.organizationName = m_dept
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
return contact
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
func getContactsMatchingPhoneNumber(_ phone: String) -> Bool {
|
|
58
|
+
var result = true
|
|
59
|
+
|
|
60
|
+
let store = CNContactStore()
|
|
61
|
+
let keysToFetch: [CNKeyDescriptor] = [CNContactGivenNameKey as CNKeyDescriptor, CNContactFamilyNameKey as CNKeyDescriptor, CNContactPhoneNumbersKey as CNKeyDescriptor]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
do {
|
|
65
|
+
let fetchRequest = CNContactFetchRequest(keysToFetch: keysToFetch)
|
|
66
|
+
try store.enumerateContacts(with: fetchRequest) { contact, _ in
|
|
67
|
+
|
|
68
|
+
for phoneNumber in contact.phoneNumbers {
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
let label = phoneNumber.label ?? "Phone"
|
|
72
|
+
let value = phoneNumber.value.stringValue
|
|
73
|
+
|
|
74
|
+
if value == phone {
|
|
75
|
+
print("Name: \(contact.givenName) \(contact.familyName)")
|
|
76
|
+
print("\(label): \(value )")
|
|
77
|
+
result = false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} catch {
|
|
82
|
+
print("Error fetching contacts: \(error)")
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return result
|
|
86
|
+
}
|
|
10
87
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import Capacitor
|
|
3
|
-
import Contacts
|
|
4
3
|
/**
|
|
5
4
|
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
5
|
* here: https://capacitorjs.com/docs/plugins/ios
|
|
7
6
|
*/
|
|
8
7
|
@objc(Plugin)
|
|
9
8
|
public class Plugin: CAPPlugin {
|
|
10
|
-
private let
|
|
9
|
+
private let contact = Contact()
|
|
10
|
+
private let screenCapture = PreventCapture()
|
|
11
11
|
|
|
12
12
|
@objc func addContact(_ call: CAPPluginCall) {
|
|
13
13
|
let name = call.getString("name") ?? ""
|
|
@@ -16,7 +16,7 @@ public class Plugin: CAPPlugin {
|
|
|
16
16
|
let dept = call.getString("dept") ?? ""
|
|
17
17
|
let ext = call.getString("ext") ?? ""
|
|
18
18
|
|
|
19
|
-
saveContact(name: name, phone: phone, email: email, dept: dept, ext: ext) { success in
|
|
19
|
+
contact.saveContact(name: name, phone: phone, email: email, dept: dept, ext: ext) { success in
|
|
20
20
|
if success {
|
|
21
21
|
call.resolve([
|
|
22
22
|
"result": true,
|
|
@@ -29,116 +29,23 @@ public class Plugin: CAPPlugin {
|
|
|
29
29
|
])
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
completion(false)
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if self.getContactsMatchingPhoneNumber(phone) {
|
|
48
|
-
|
|
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
|
-
}
|
|
34
|
+
@objc func setScreenCaptureDisabled(_ call: CAPPluginCall) {
|
|
35
|
+
screenCapture.screenCapturePrevent(webview: (self.bridge?.webView)!, completion:{ success in
|
|
36
|
+
if success {
|
|
37
|
+
call.resolve([
|
|
38
|
+
"result": true,
|
|
39
|
+
"message": "완료"
|
|
40
|
+
])
|
|
61
41
|
} else {
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return contact
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
func getContactsMatchingPhoneNumber(_ phone: String) -> Bool {
|
|
87
|
-
var result = true
|
|
88
|
-
|
|
89
|
-
let store = CNContactStore()
|
|
90
|
-
let keysToFetch: [CNKeyDescriptor] = [CNContactGivenNameKey as CNKeyDescriptor, CNContactFamilyNameKey as CNKeyDescriptor, CNContactPhoneNumbersKey as CNKeyDescriptor]
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
107
|
-
}
|
|
108
|
-
}
|
|
42
|
+
call.resolve([
|
|
43
|
+
"result": false,
|
|
44
|
+
"message": "실패"
|
|
45
|
+
])
|
|
109
46
|
}
|
|
110
|
-
}
|
|
111
|
-
print("Error fetching contacts: \(error)")
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return result
|
|
47
|
+
})
|
|
115
48
|
}
|
|
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
|
-
// }
|
|
49
|
+
|
|
143
50
|
}
|
|
144
51
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
import WebKit
|
|
4
|
+
|
|
5
|
+
@objc public class PreventCapture: NSObject {
|
|
6
|
+
|
|
7
|
+
@objc public func screenCapturePrevent(webview: WKWebView, completion: @escaping (Bool) -> Void) {
|
|
8
|
+
webview.makeSecure()
|
|
9
|
+
completion(true)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
extension UIView {
|
|
14
|
+
func makeSecure() {
|
|
15
|
+
DispatchQueue.main.async {
|
|
16
|
+
let textField = UITextField()
|
|
17
|
+
textField.isSecureTextEntry = true
|
|
18
|
+
self.addSubview(textField)
|
|
19
|
+
|
|
20
|
+
let backView = UIView(frame: self.frame)
|
|
21
|
+
let image = UIImageView(image: UIImage(named: "background", in: Bundle(for: PreventCapture.self), compatibleWith: nil))
|
|
22
|
+
image.frame = backView.bounds
|
|
23
|
+
|
|
24
|
+
backView.backgroundColor = UIColor.lightGray
|
|
25
|
+
backView.addSubview(image)
|
|
26
|
+
|
|
27
|
+
textField.insertSubview(backView, at: 0)
|
|
28
|
+
|
|
29
|
+
textField.layer.removeFromSuperlayer()
|
|
30
|
+
self.layer.superlayer?.insertSublayer(textField.layer, at: 0)
|
|
31
|
+
textField.layer.sublayers?.last?.addSublayer(self.layer)
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
Binary file
|
|
Binary file
|