일반 함수
앱 & 사이트 에서 사용자 식별을 위하여 사용자가 선택한 주소를 반환함.
필수
appAction : login필수
appName : 링크 참조필수
appCallbackType : 링크 참조필수
appCallback : 링크 참조- appReqKey : 요청 식별값
- appIcon : 링크 참조
- network : 링크 참조
필수
appReqKey : 링크 참조필수
code : 0000(성공), 9999(취소), 0001~9998(오류)필수
message : 성공시 빈 문자열, 실패시 오류 메시지필수
network : 1(Mainnet) or 5(TestNet)필수
data : 성공시 선택된 주소, 실패시 빈 문자열필수
name : 성공시 선택된 주소의 명칭, 실패시 빈 문자열필수
timestamp : 서버 시간필수
sign: address + "|" + timestamp 를 RSA 로 서명한값. 사전에 제공된 공개키로 서명이 올바른지 확인하여야함.
Android(Java)
iOS(Swift)
HTML(Mobule Web)
1
public class LoginTest {
2
protected ActivityResultLauncher<Intent>
3
mStartForResult = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
4
int i = result.getResultCode();
5
if (i == Activity.RESULT_OK) {
6
Intent intent = result.getData();
7
if (intent == null) {
8
return;
9
}
10
Bundle bundle = intent.getExtras();
11
String code = bundle.getString("code", "");
12
switch (code) {
13
case "0000":
14
bindingResult.viResult.setText(R.string.success);
15
break;
16
case "9999":
17
bindingResult.viResult.setText(R.string.cancel_by_user);
18
break;
19
default:
20
bindingResult.viResult.setText(R.string.error);
21
break;
22
}
23
bindingResult.viResultCode.setText(code);
24
bindingResult.viResultMessage.setText(bundle.getString("message", ""));
25
bindingResult.viResultTXID.setText(bundle.getString("txid", ""));
26
} else if (i == Activity.RESULT_CANCELED) {
27
bindingResult.viResult.setText(R.string.cancel_by_user);
28
bindingResult.viResultCode.setText("");
29
bindingResult.viResultMessage.setText("");
30
bindingResult.viResultTXID.setText("");
31
}
32
});
33
34
public void doLogin(){
35
Uri params = Uri.parse("metawallet://co.inblock");
36
Intent intent = new Intent(Intent.ACTION_VIEW, params);
37
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
38
intent.putExtra("appCction", "login");
39
intent.putExtra("appReqKey", "REQUEST_KEY");
40
intent.putExtra("network", "1");
41
intent.putExtra("appUrl", "https://www.example.com");
42
intent.putExtra("appIcon", "https://www.example.com/images/icon.png");
43
intent.putExtra("appName", "Example");
44
intent.putExtra("appCallbankType", "intent");
45
mStartForResult.launch(intent);
46
}
47
}
48
1
// Call MetaWallet
2
var requestComponents: URLComponents = URLComponents()
3
requestComponents.scheme = "metawallet://"
4
requestComponents.host = "co.inblock"
5
requestComponents.queryItems = [
6
URLQueryItem(name: "appReqKey", value: topic),
7
URLQueryItem(name: "appName", value: appName ?? name),
8
URLQueryItem(name: "appAction", value: "connect")
9
URLQueryItem(name: "appIcons", value: iconUrl!)
10
URLQueryItem(name: "appCallbackType", value: "universallink")
11
URLQueryItem(name: "appCallback", value: "smapleapp://metawallet")
12
]
13
14
if UIApplication.shared.canOpenURL(requestComponents.url) {
15
UIApplication.shared.open(url, options: [.universalLinksOnly:true]){ isSuccess in
16
if isSuccess {
17
// Success
18
} else {
19
// failed open app
20
}
21
}
22
}
23
24
//
25
// ==================================
26
//
27
28
// Result Process
29
30
// SceneDelegate.swift
31
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
32
guard let _ = (scene as? UIWindowScene) else { return }
33
34
if let userActivity = connectionOptions.userActivities.first {
35
self.scene(scene, continue: userActivity)
36
}
37
}
38
39
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
40
if let url = userActivity.webpageURL {
41
if url.host == nil || url.scheme == nil {
42
return
43
}
44
45
if url.host != "smapleapp" {
46
return
47
}
48
49
guard let param = url.parameters else {
50
return
51
}
52
53
if let reqKey = param["reqKey"] as? String {
54
if !RequestQueue.shared.pop(key: reqKey) {
55
return
56
}
57
58
let notificationName = NSNotification.Name(rawValue: reqKey)
59
NotificationCenter.default.post(name: notificationName, object: param)
60
61
return true
62
}
63
}
64
}
65
1
<a href="metawallet://co.inblock?
2
?appCction=connect
3
&appReqKey=REQUEST_KEY
4
&appUrl=https://wallet.metacoin.network
5
&name=샘플사이트
6
&icons=https://wallet.metacoin.network/favicon.png
7
&callbackType=url
8
&callback=https://wallet.metacoin.network/app/callback">
9
Click to Metawallet Link</a>
Last modified 7mo ago