Ghi dữ liệu vào pasteboard (pasteboard.write)
Khai báo
pasteboard.write(data [, uti ])
pasteboard.write(item [, options ])
pasteboard.write(items [, options ])
Tham số
-
data
String. Nội dung cần ghi vào pasteboard hệ thống.
Table. Một mục pasteboard mà các khóa là UTIs và giá trị là dữ liệu chuỗi. (hỗ trợ từ phiên bản 20260428)
Table. Một danh sách các mục pasteboard. (hỗ trợ từ phiên bản 20260428) -
uti
String, tùy chọn. Uniform Type Identifiers. Mặc định: "public.utf8-plain-text". -
options Table, tùy chọn. (hỗ trợ từ phiên bản 20260428)
local_only: Boolean. Giữ nội dung chỉ trên thiết bị này. Hỗ trợ trên iOS 10 trở lên.
expiration_date: Number. Thời gian Unix tính bằng giây. Hỗ trợ trên iOS 10 trở lên.Cấu trúc mục pasteboard
{
["public.utf8-plain-text"] = "nội dung văn bản đơn giản",
["public.rtf"] = "dữ liệu RTF",
["public.html"] = "dữ liệu HTML",
["public.png"] = "dữ liệu PNG nhị phân",
...
}
Giá trị trả về
- success
Boolean. Trả vềtruekhi ghi thành công; ngược lại trả vềfalse.
Mô tả
Ghi nội dung vào pasteboard hệ thống.
Khi cung cấpitemhoặcitems, nhiều biểu diễn sẽ được ghi vào cùng một mục pasteboard. iOS 9 bỏ quaoptions.
Ví dụ
pasteboard.write("hello") -- Ghi văn bản "hello" vào pasteboard
--
pasteboard.write(screen.image():png_data(), 'public.png') -- Ghi một ảnh chụp màn hình vào pasteboard
--
pasteboard.write([[{\rtf1\ansi\deff0
{\fonttbl{\f0 Helvetica;}}
{\colortbl;\red255\green0\blue0;}
\f0\fs32 normal {\b bold} {\i italic} \cf1 red\cf0\par
\u20320?\u22909?
}]], "public.rtf") -- Ghi văn bản RTF phong phú vào pasteboard
-- Từ phiên bản 20260428 trở lên hỗ trợ ghi nhiều biểu diễn vào một mục
pasteboard.write({
["public.utf8-plain-text"] = "normal bold italic red\nHello",
["public.rtf"] = [[{\rtf1\ansi\deff0
{\fonttbl{\f0 Helvetica;}}
{\colortbl;\red255\green0\blue0;}
\f0\fs32 normal {\b bold} {\i italic} \cf1 red\cf0\par
Hello
}]],
["public.html"] = [[<p>normal <b>bold</b> <i>italic</i> <span style="color:red">red</span><br>Hello</p>]],
}, {
local_only = true,
expiration_date = os.time() + 3600,
})
Lưu ý: Sử dụng screen.image