@hanwha-ss1/plugin 0.1.1 → 0.1.3
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/android/src/main/java/com/plugin/contact/Contact.java +30 -13
- package/ios/Plugin/Contact.swift +82 -5
- package/ios/Plugin/ContactPlugin.m +1 -0
- package/ios/Plugin/ContactPlugin.swift +16 -109
- package/ios/Plugin/PreventCapture.swift +39 -0
- package/ios/Plugin/background.png +0 -0
- package/ios/Plugin/watermark.png +0 -0
- package/package.json +1 -1
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
package com.plugin.contact;
|
|
2
2
|
|
|
3
|
+
import android.Manifest;
|
|
3
4
|
import android.app.Activity;
|
|
4
5
|
import android.content.ContentProviderOperation;
|
|
5
6
|
import android.content.ContentResolver;
|
|
6
7
|
import android.content.OperationApplicationException;
|
|
8
|
+
import android.content.pm.PackageManager;
|
|
7
9
|
import android.database.Cursor;
|
|
8
10
|
import android.net.Uri;
|
|
9
11
|
import android.os.RemoteException;
|
|
10
12
|
import android.provider.ContactsContract;
|
|
11
13
|
import android.util.Log;
|
|
12
14
|
|
|
15
|
+
import androidx.core.app.ActivityCompat;
|
|
16
|
+
import androidx.core.content.ContextCompat;
|
|
17
|
+
|
|
13
18
|
import java.util.ArrayList;
|
|
14
19
|
|
|
15
20
|
|
|
@@ -29,25 +34,37 @@ public class Contact {
|
|
|
29
34
|
* 연락처 저장
|
|
30
35
|
*
|
|
31
36
|
* @param activity
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
+
* @param name 성명
|
|
38
|
+
* @param mobilePhoneNumber 전화번호
|
|
39
|
+
* @param email 이메일
|
|
40
|
+
* @param departmentName 소속
|
|
41
|
+
* @param extensionNumber 내선번호
|
|
37
42
|
*/
|
|
38
43
|
public void save(Activity activity, String name, String email, String mobilePhoneNumber, String extensionNumber, String departmentName, OnResult result) {
|
|
39
|
-
if(
|
|
40
|
-
if(
|
|
41
|
-
result
|
|
44
|
+
if(checkPermission(activity)) {
|
|
45
|
+
if (hasContacts(activity, mobilePhoneNumber)) {
|
|
46
|
+
if (result != null) {
|
|
47
|
+
result.onFail();
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
saveContacts(activity, name, email, mobilePhoneNumber, extensionNumber, departmentName);
|
|
51
|
+
result.onSuccess();
|
|
42
52
|
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private boolean checkPermission(Activity activity) {
|
|
57
|
+
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED
|
|
58
|
+
&& ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
|
|
59
|
+
return true;
|
|
43
60
|
} else {
|
|
44
|
-
|
|
45
|
-
|
|
61
|
+
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS, }, 101);
|
|
62
|
+
return false;
|
|
46
63
|
}
|
|
47
64
|
}
|
|
48
65
|
|
|
49
66
|
public boolean hasContacts(Activity activity, String key) {
|
|
50
|
-
ArrayList<String>
|
|
67
|
+
ArrayList<String> names = new ArrayList<>();
|
|
51
68
|
ContentResolver resolver = activity.getContentResolver();
|
|
52
69
|
|
|
53
70
|
Uri phoneUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(key));
|
|
@@ -62,13 +79,13 @@ public class Contact {
|
|
|
62
79
|
while (cursor.moveToNext()) {
|
|
63
80
|
int nameIndex = cursor.getColumnIndex(projection[0]);
|
|
64
81
|
String name = cursor.getString(nameIndex);
|
|
65
|
-
|
|
82
|
+
names.add(name);
|
|
66
83
|
}
|
|
67
84
|
}
|
|
68
85
|
|
|
69
86
|
cursor.close();
|
|
70
87
|
|
|
71
|
-
return
|
|
88
|
+
return names.size() > 0;
|
|
72
89
|
}
|
|
73
90
|
|
|
74
91
|
public void saveContacts(Activity activity, String name, String email, String mobilePhoneNumber, String extensionNumber, String departmentName) {
|
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,39 @@
|
|
|
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
|
+
textField.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
|
|
20
|
+
textField.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
|
|
21
|
+
|
|
22
|
+
let backView = UIView(frame: self.frame)
|
|
23
|
+
let image = UIImageView(image: UIImage(named: "background", in: Bundle(for: PreventCapture.self), compatibleWith: nil))
|
|
24
|
+
image.frame = backView.bounds
|
|
25
|
+
|
|
26
|
+
backView.backgroundColor = UIColor.lightGray
|
|
27
|
+
backView.addSubview(image)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
textField.insertSubview(backView, at: 0)
|
|
31
|
+
|
|
32
|
+
// 캡쳐하려는 뷰의 레이어를 textField.layer 사이에 끼워넣기
|
|
33
|
+
|
|
34
|
+
self.layer.superlayer?.insertSublayer(textField.layer, at: 0)
|
|
35
|
+
textField.layer.sublayers?.last?.addSublayer(self.layer)
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
Binary file
|
|
Binary file
|