1
|
#import <
Cordova
/CDV.h>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import
Foundation
@objc
(
HWPHanggeSwiftPlugin
)
class
HanggeSwiftPlugin
:
CDVPlugin
{
//驗證口令方法
func
verifyPassword(command:
CDVInvokedUrlCommand
)
{
//返回結果
var
pluginResult:
CDVPluginResult
?
//獲取參數
let
password = command.arguments[0]
as
?
String
//開始驗證
if
password ==
nil
|| password ==
""
{
pluginResult =
CDVPluginResult
(status:
CDVCommandStatus_ERROR
,
messageAsString:
"口令不能爲空"
)
}
else
if
password !=
"hangge"
{
pluginResult =
CDVPluginResult
(status:
CDVCommandStatus_ERROR
,
messageAsString:
"口令不正確"
)
}
else
{
pluginResult =
CDVPluginResult
(status:
CDVCommandStatus_OK
)
}
//發送結果
self
.commandDelegate.sendPluginResult(pluginResult, callbackId: command.callbackId)
}
}
|
1
2
3
|
<
feature
name
=
"HanggeSwiftPlugin"
>
<
param
name
=
"ios-package"
value
=
"HWPHanggeSwiftPlugin"
/>
</
feature
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
<!DOCTYPE html>
<html>
<head>
<title>口令驗證</title>
<meta http-equiv=
"Content-type"
content=
"text/html; charset=utf-8"
>
<script type=
"text/javascript"
charset=
"utf-8"
src=
"cordova.js"
></script>
<script type=
"text/javascript"
charset=
"utf-8"
>
//開始驗證
function
verify() {
//獲取輸入的口令
var
password = document.getElementById(
"pwd"
).value;
//調用自定義的驗證插件
Cordova.exec(successFunction, failFunction,
"HanggeSwiftPlugin"
,
"verifyPassword"
, [password]);
}
//驗證成功
function
successFunction(){
alert(
"口令驗證成功!"
);
}
//驗證失敗
function
failFunction(message){
alert(
"驗證失敗:"
+message);
}
</script>
<style>
* {
font-size:1em;
}
</style>
</head>
<body style=
"padding-top:50px;"
>
<input type=
"text"
id=
"pwd"
>
<button onclick=
"verify();"
>驗證</button>
</body>
</html>
|