Chuyển tới nội dung chính

Get data event

1. getMultipleUserData()

Event Code: GET_MULTIPLE_USER_DATA - Lấy nhiều trường dữ liệu người dùng từ host app.

Request data (data is JSON.stringify())

FieldTypeRequiredDescription
dataNamesarrayoptionalDanh sách data cần lấy ["age", "userName", "fullName", "phoneNumber", "avatar", "gender", "birthday", "idNo"]

Response

FieldTypeRequiredDescription
agestringoptional
userNamestringoptional
fullNamestringoptional
phoneNumberstringoptional
avatarstringoptional
genderstringoptional
birthdaystringoptional
idNostringoptional

Ví dụ sử dụng (npm package)

import { getMultipleUserData, isSuccess } from 'vdf-webview-miniapp-sdk'

const res = await getMultipleUserData({ data: {
dataNames: ["age", "userName", "fullName", "phoneNumber", "avatar", "gender", "birthday", "idNo"]
} })
if (isSuccess(res)) {
console.log(res.age)
console.log(res.userName)
console.log(res.fullName)
}

Sử dụng với bundle.js

const res = await WebviewSdk.getMultipleUserData({ data: {
dataNames: ["age", "userName", "fullName", "phoneNumber", "avatar", "gender", "birthday", "idNo"]
} })
if (WebviewSdk.isSuccess(res)) {
console.log(res.age)
console.log(res.userName)
console.log(res.fullName)
}

2. clearPermissionCache()

Event Code: CLEAR_PERMISSION_CACHE - Xóa tất cả quyền đã cache ở local.

Request

Không có tham số riêng, nhưng data là bắt buộc — truyền object rỗng: { data: {} }

Response

No response data

Ví dụ sử dụng (npm package)

import { clearPermissionCache, isSuccess } from 'vdf-webview-miniapp-sdk'

const res = await clearPermissionCache({ data: {} })
if (isSuccess(res)) {
console.log('Thành công')
}

Sử dụng với bundle.js

const res = await WebviewSdk.clearPermissionCache({ data: {} })
if (WebviewSdk.isSuccess(res)) {
console.log('Thành công')
}

3. getLocalAuthenticationStatus()

Event Code: GET_LOCAL_AUTHENTICATION_STATUS - lấy trạng thái xác thực sinh trắc học (vân tay, Face ID).

Request

No request parameters

Response

FieldTypeRequiredDescription
isHardwareSupportStrongBiometricbooleanoptionalPhần cứng hỗ trợ sinh trắc mạnh
isHardwareSupportBiometricbooleanoptionalPhần cứng hỗ trợ sinh trắc
isDeviceSecurebooleanoptionalThiết bị đã bật bảo mật
canAuthenticateWithDeviceCredentialbooleanoptionalCó thể xác thực bằng PIN/password
canAuthenticateWithBiometricsbooleanoptionalCó thể xác thực bằng sinh trắc
canAuthenticateWithStrongBiometricsbooleanoptionalCó thể xác thực bằng sinh trắc mạnh

Ví dụ sử dụng (npm package)

import { getLocalAuthenticationStatus, isSuccess } from 'vdf-webview-miniapp-sdk'

const res = await getLocalAuthenticationStatus()
if (isSuccess(res)) {
console.log(res.isHardwareSupportStrongBiometric)
console.log(res.isHardwareSupportBiometric)
console.log(res.isDeviceSecure)
}

Sử dụng với bundle.js

const res = await WebviewSdk.getLocalAuthenticationStatus()
if (WebviewSdk.isSuccess(res)) {
console.log(res.isHardwareSupportStrongBiometric)
console.log(res.isHardwareSupportBiometric)
console.log(res.isDeviceSecure)
}

4. getContacts()

Event Code: GET_CONTACTS - Lấy danh sách contacts từ danh bạ hệ thống.

Request data

FieldTypeRequiredDescription
filterobjectoptional{ "contactName": "John" }
pagerobjectoptional{ "pageNumber": 1, "limitRow": 100 }

Response data

FieldTypeRequiredDescription
contactListarrayoptional[ { "contactName": "John Doe", "contactNumber": "0901234567", "contactAvt": "base64_image_string" } ]
countContactsnumberoptional1

Ví dụ sử dụng (npm package)

import { getContacts, isSuccess } from 'vdf-webview-miniapp-sdk'

const res = await getContacts({ data: {
filter: { "contactName": "John" },
pager: { "pageNumber": 1, "limitRow": 100 }
} })
if (isSuccess(res)) {
console.log(res.data.contactList)
console.log(res.data.countContacts)
}

Sử dụng với bundle.js

const res = await WebviewSdk.getContacts({ data: {
filter: { "contactName": "John" },
pager: { "pageNumber": 1, "limitRow": 100 }
} })
if (WebviewSdk.isSuccess(res)) {
console.log(res.data.contactList)
console.log(res.data.countContacts)
}

5. getLocation()

Event Code: GET_LOCATION - Lấy vị trí GPS hiện tại của thiết bị. Phải có quyền LOCATION_PERMISSION trước khi sử dụng API này.

Request

No request parameters

Response

FieldTypeRequiredDescription
latitudeanyoptionalVĩ độ 21.0285
longgitudeanyoptionalKinh độ 105.8542

Ví dụ sử dụng (npm package)

import { getLocation, isSuccess } from 'vdf-webview-miniapp-sdk'

const res = await getLocation()
if (isSuccess(res)) {
console.log(res.latitude)
console.log(res.longgitude)
}

Sử dụng với bundle.js

const res = await WebviewSdk.getLocation()
if (WebviewSdk.isSuccess(res)) {
console.log(res.latitude)
console.log(res.longgitude)
}

6. shareTextContent()

Event Code: SHARE_TEXT_CONTENT - Mở dialog chia sẻ nội dung text.

Request data (data is JSON.stringify())

FieldTypeRequiredDescription
contentstringoptionalText nội dung Check out this amazing product!

Response

No response data

Ví dụ sử dụng (npm package)

import { shareTextContent, isSuccess } from 'vdf-webview-miniapp-sdk'

const res = await shareTextContent({ data: {
content: "Check out this amazing product!"
} })
if (isSuccess(res)) {
console.log('Thành công')
}

Sử dụng với bundle.js

const res = await WebviewSdk.shareTextContent({ data: {
content: "Check out this amazing product!"
} })
if (WebviewSdk.isSuccess(res)) {
console.log('Thành công')
}

7. miniAppToken()

Event Code: MINI_APP_TOKEN - Get mini app token

Request

No request parameters

Response data

FieldTypeRequiredDescription
miniAppTokenstringrequiredminiAppToken

Ví dụ sử dụng (npm package)

import { miniAppToken, isSuccess } from 'vdf-webview-miniapp-sdk'

const res = await miniAppToken()
if (isSuccess(res)) {
console.log(res.data.miniAppToken)
}

Sử dụng với bundle.js

const res = await WebviewSdk.miniAppToken()
if (WebviewSdk.isSuccess(res)) {
console.log(res.data.miniAppToken)
}

8. expiredSession()

Event Code: EXPIRED_SESSION - Session expiration event, Delegate cho host app xử lý

Request

No request parameters

Response

No response data

Ví dụ sử dụng (npm package)

import { expiredSession, isSuccess } from 'vdf-webview-miniapp-sdk'

const res = await expiredSession()
if (isSuccess(res)) {
console.log('Thành công')
}

Sử dụng với bundle.js

const res = await WebviewSdk.expiredSession()
if (WebviewSdk.isSuccess(res)) {
console.log('Thành công')
}

9. saveImageToGallery()

Event Code: SAVE_IMAGE_TO_GALLERY - Lưu ảnh vào bộ sưu tập

Request data

FieldTypeRequiredDescription
typestringoptionalLoại nguồn ảnh. Giá trị: "url" hoặc "base64" (không phân biệt hoa thường) url
datastringoptionalNội dung ảnh: đường dẫn URL đầy đủ (nếu type=url) hoặc chuỗi Base64 (nếu type=base64) https://media-cdn-v2.laodong.vn/storage/newsportal/2023/8/26/1233821/Giai-Nhat--Dem-Sai-G.jpg

Response data

FieldTypeRequiredDescription
successbooleanrequiredThanh cong

Ví dụ sử dụng (npm package)

import { saveImageToGallery, isSuccess } from 'vdf-webview-miniapp-sdk'

const res = await saveImageToGallery({ data: {
type: "url",
data: "https://media-cdn-v2.laodong.vn/storage/newsportal/2023/8/26/1233821/Giai-Nhat--Dem-Sai-G.jpg"
} })
if (isSuccess(res)) {
console.log(res.data.success)
}

Sử dụng với bundle.js

const res = await WebviewSdk.saveImageToGallery({ data: {
type: "url",
data: "https://media-cdn-v2.laodong.vn/storage/newsportal/2023/8/26/1233821/Giai-Nhat--Dem-Sai-G.jpg"
} })
if (WebviewSdk.isSuccess(res)) {
console.log(res.data.success)
}

10. saveFile()

Event Code: SAVE_FILE - Lưu file vào thư mục

Request data

FieldTypeRequiredDescription
urlstringoptionalĐường dẫn URL đầy đủ của File https://pdfobject.com/pdf/sample.pdf
fileNamestringoptionalTên file, không bắt buộc, nếu không truyền thì sẽ tự động lấy tên file trong url test_file

Response data

FieldTypeRequiredDescription
successbooleanrequiredThanh cong

Ví dụ sử dụng (npm package)

import { saveFile, isSuccess } from 'vdf-webview-miniapp-sdk'

const res = await saveFile({ data: {
url: "https://pdfobject.com/pdf/sample.pdf",
fileName: "test_file"
} })
if (isSuccess(res)) {
console.log(res.data.success)
}

Sử dụng với bundle.js

const res = await WebviewSdk.saveFile({ data: {
url: "https://pdfobject.com/pdf/sample.pdf",
fileName: "test_file"
} })
if (WebviewSdk.isSuccess(res)) {
console.log(res.data.success)
}

11. initRequest()

Event Code: INIT_REQUEST - Get init event

Request

No request parameters

Response

No response data

Ví dụ sử dụng (npm package)

import { initRequest, isSuccess } from 'vdf-webview-miniapp-sdk'

const res = await initRequest()
if (isSuccess(res)) {
console.log('Thành công')
}

Sử dụng với bundle.js

const res = await WebviewSdk.initRequest()
if (WebviewSdk.isSuccess(res)) {
console.log('Thành công')
}