Links
Modules
|
device
提供设备相关属性的查询,以及设备功能的访问
当框架初始完成后,device 模块提供下列属性:
- device.platform 返回当前运行平台的名字,可用值: ios, android, mac, windows.
- device.model 返回设备型号,可用值: unknown, iphone, ipad
- device.language 返回设备当前使用的语言,可用值:
- cn:中文
- fr:法语
- it:意大利语
- gr:德语
- sp:西班牙语
- ru:俄语
- jp:日语
- en:英语
- device.writablePath 返回设备上可以写入数据的首选路径:
- iOS 上返回应用程序所在的 Documents 目录
- Android 上返回存储卡的根目录
- 其他平台的返回值由 quick-x-player 决定
- device.cachePath 返回设备上可以写入数据的缓存目录:
- iOS 上返回应用程序所在的 Library/Caches 目录
- 其他平台的返回值同 device.writablePath
- device.directorySeparator 目录分隔符,在 Windows 平台上是 “\”,其他平台都是 “/”
- device.pathSeparator 路径分隔符,在 Windows 平台上是 “;”,其他平台都是 “:”
Functions
-
device.showActivityIndicator()
device.showActivityIndicator()
显示活动指示器
在 iOS 和 Android 设备上显示系统的活动指示器,可以用于阻塞操作时通知用户需要等待。
-
device.hideActivityIndicator()
device.hideActivityIndicator()
隐藏正在显示的活动指示器
-
device.showAlert()
device.showAlert(title, message, buttonLabels, listener)
显示一个包含按钮的弹出对话框
local function onButtonClicked(event)
if event.buttonIndex == 1 then
.... 玩家选择了 YES 按钮
else
.... 玩家选择了 NO 按钮
end
end
device.showAlert("Confirm Exit", "Are you sure exit game ?", {"YES", "NO"}, onButtonClicked)
当没有指定按钮标题时,对话框会默认显示一个“OK”按钮。
回调函数获得的表格中,buttonIndex 指示玩家选择了哪一个按钮,其值是按钮的显示顺序。
Parameters
- string title 对话框标题
- string message 内容
- table buttonLabels 包含多个按钮标题的表格对象
- function listener 回调函数
-
device.cancelAlert()
device.cancelAlert()
取消正在显示的对话框。
提示:取消对话框,不会执行显示对话框时指定的回调函数。
-
device.getOpenUDID()
device.getOpenUDID()
返回设备的 OpenUDID 值
OpenUDID 是为设备仿造的 UDID(唯一设备识别码),可以用来识别用户的设备。
但 OpenUDID 存在下列问题:
- 如果删除了应用再重新安装,获得的 OpenUDID 会发生变化
- iOS 7 不支持 OpenUDID
Returns
-
device.openURL()
device.openURL(url)
用浏览器打开指定的网址
-- 打开网页
device.openURL("http://dualface.github.com/quick-cocos2d-x/")
-- 打开设备上的邮件程序,并创建新邮件,填入收件人地址
device.openURL("mailto:nobody@mycompany.com")
-- 增加主题和内容
local subject = string.urlencode("Hello")
local body = string.urlencode("How are you ?")
device.openURL(string.format("mailto:nobody@mycompany.com?subject=%s&body=%s", subject, body))
-- 打开设备上的拨号程序
device.openURL("tel:123-456-7890")
Parameters
-
device.showInputBox()
device.showInputBox(title, message, defaultValue)
显示一个输入框,并返回用户输入的内容。
当用户点击取消按钮时,showInputBox() 函数返回空字符串。
Parameters
- string title 对话框标题
- string message 提示信息
- string defaultValue 输入框默认值
Returns
|