@hanwha-ss1/plugin 0.2.4 → 0.2.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.
@@ -5,6 +5,7 @@ import Contacts
5
5
  * Please read the Capacitor iOS Plugin Development Guide
6
6
  * here: https://capacitorjs.com/docs/plugins/ios
7
7
  */
8
+
8
9
  public class AuthPlugin: CAPPlugin {
9
10
  private let implementation = AuthService()
10
11
 
@@ -3,7 +3,32 @@ import UIKit
3
3
  import LocalAuthentication
4
4
  import Capacitor
5
5
 
6
+
7
+
6
8
  public class AuthService: NSObject {
9
+
10
+ func biometricType() -> String {
11
+ let authContext = LAContext()
12
+ if #available(iOS 11.0, *) {
13
+ let _ = authContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
14
+ switch(authContext.biometryType) {
15
+ case .touchID:
16
+ return "TOUCH_ID"
17
+ case .faceID:
18
+ return "FACE_ID"
19
+ case .none:
20
+ return "NONE"
21
+ case .opticID:
22
+ return "OPTIC_ID"
23
+ @unknown default:
24
+ return "NONE"
25
+ }
26
+ } else {
27
+ return authContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) ? "TOUCH_ID" : "NONE"
28
+ }
29
+ }
30
+
31
+
7
32
  public func authService(call: CAPPluginCall) {
8
33
 
9
34
  let context = LAContext()
@@ -14,11 +39,11 @@ public class AuthService: NSObject {
14
39
  let reason = "생체 인식을 사용하여 로그인합니다."
15
40
 
16
41
  // Face ID 또는 Touch ID 인증 시도
17
- context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { success, error in
42
+ context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, error in
18
43
  DispatchQueue.main.async {
19
44
  if success {
20
45
  // 인증 성공
21
- call.resolve(self.settingResult(result: true, message: "생체 인식에 성공 하였습니다."))
46
+ call.resolve(self.settingResult(result: true, message: "성공", code: 0))
22
47
  } else {
23
48
  // 인증 실패
24
49
  if let error = error as NSError? {
@@ -30,30 +55,29 @@ public class AuthService: NSObject {
30
55
  message = "사용자가 취소했습니다."
31
56
  case LAError.userFallback.rawValue:
32
57
  message = "비밀번호를 입력하여 로그인하세요."
33
- case LAError.biometryNotAvailable.rawValue:
34
- message = "생체 인식을 사용할 수 없습니다."
35
- case LAError.biometryNotEnrolled.rawValue:
36
- message = "생체 인식이 등록되어 있지 않습니다."
58
+
37
59
  case LAError.biometryLockout.rawValue:
38
60
  message = "생체 인식이 잠겼습니다. 잠시 후 다시 시도하세요."
39
61
  default:
40
62
  message = "생체 인식에 실패했습니다."
41
63
  }
42
- call.resolve(self.settingResult(result: false, message: message))
64
+ call.resolve(self.settingResult(result: false, message: message, code: error.code))
43
65
  }
44
66
  }
45
67
  }
46
68
  }
47
69
  } else {
48
- call.resolve(self.settingResult(result: false, message: "생체 인식을 사용할 수 없습니다."))
70
+ call.resolve(self.settingResult(result: false, message: "생체 인식을 사용할 수 없습니다.", code:1))
49
71
  }
50
72
 
51
73
  }
52
74
 
53
- func settingResult(result: Bool, message: String) -> [String: Any] {
75
+ func settingResult(result: Bool, message: String, code: Int) -> [String: Any] {
76
+
54
77
  return [
55
- "result": result,
56
- "message": message
78
+ "isAvailable": result,
79
+ "biometryType": biometricType(),
80
+ "errorCode": code
57
81
  ]
58
82
  }
59
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanwha-ss1/plugin",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",