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
4
5
6
7
8
9
10
11
12
13
|
'use strict'
;
var
exec = require(
'cordova/exec'
);
var
HanggeSwiftPlugin = {
verifyPassword:
function
(sendMsg, onSuccess, onFail) {
return
exec(onSuccess, onFail,
'HanggeSwiftPlugin'
,
'verifyPassword'
, [sendMsg]);
}
};
module.exports = HanggeSwiftPlugin;
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
id
=
"hangge-swift-plugin"
version
=
"0.1"
>
<
name
>HanggeSwiftPlugin</
name
>
<
description
>This plugin use to verify password</
description
>
<
js-module
src
=
"hangge-swift-plugin.js"
>
<
clobbers
target
=
"window.HanggeSwiftPlugin"
/>
</
js-module
>
<!-- iOS -->
<
platform
name
=
"ios"
>
<
config-file
target
=
"config.xml"
parent
=
"/*"
>
<
feature
name
=
"HanggeSwiftPlugin"
>
<
param
name
=
"ios-package"
value
=
"HWPHanggeSwiftPlugin"
/>
</
feature
>
</
config-file
>
<
source-file
src
=
"src/ios/HanggeSwiftPlugin.swift"
/>
</
platform
>
</
plugin
>
|
1
|
cordova plugin add cordova-plugin-add-swift-support
|
1
|
cordova plugin add ~/Documents/HanggeSwiftPlugin
|
1
|
cordova plugin rm hangge-swift-plugin
|
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>
|
1
|
cordova build
|
1
|
cordova emulate ios
|
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
|
<!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;
//調用自定義的驗證插件
HanggeSwiftPlugin.verifyPassword(password, successFunction, failFunction);
}
//驗證成功
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>
|
1
2
3
4
5
6
7
8
9
10
11
|
//開始驗證
function
verify() {
//獲取輸入的口令
var
password = document.getElementById(
"pwd"
).value;
//調用自定義的驗證插件
HanggeSwiftPlugin.verifyPassword(password,
function
() { alert(
"口令驗證成功!"
);},
function
(message){
alert(
"驗證失敗:"
+message);
});
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
//開始驗證
function
verify() {
//獲取輸入的口令
var
password = document.getElementById(
"pwd"
).value;
//調用自定義的驗證插件
if
(window.HanggeSwiftPlugin) {
HanggeSwiftPlugin.verifyPassword(password,
function
() { alert(
"口令驗證成功!"
);},
function
(message){
alert(
"驗證失敗:"
+message);
});
}
else
{
alert(
"未安裝驗證插件!"
);
}
}
|