c1_lua/lua/app/common/device_helper.lua
2023-04-03 10:59:13 +08:00

53 lines
1.7 KiB
Lua

local DeviceHelper = {}
local ThinkingAnalyticsAPI = CS.ThinkingAnalytics.ThinkingAnalyticsAPI
local PresetProperties = CS.ThinkingAnalytics.ThinkingAnalyticsAPI.GetPresetProperties()
-- 提供给其他模块的接口 ***************************************************************
-- 获取device_model
function DeviceHelper:getDeviceModel()
local name = CS.UnityEngine.SystemInfo.deviceModel
if not name or name == "" then
name = PresetProperties and PresetProperties.DeviceModel or ""
end
return name
end
-- 获取device_id
function DeviceHelper:getDeviceId()
-- local id = ""
-- if ThinkingAnalyticsAPI then
-- id = ThinkingAnalyticsAPI:GetDeviceId() or ""
-- end
-- if not id or id == "" then
-- id = CS.UnityEngine.SystemInfo.deviceUniqueIdentifier or ""
-- end
-- return id
return CS.UnityEngine.SystemInfo.deviceUniqueIdentifier
end
-- 获取os_version
function DeviceHelper:getOSVersion()
local version = CS.UnityEngine.SystemInfo.operatingSystem
if not version or version == "" then
version = PresetProperties and PresetProperties.OSVersion or ""
end
return version
end
-- 获取网络状态
function DeviceHelper:getNetworkType()
local networkType = "WIFI"
if CS.UnityEngine.Application.internetReachability == CS.UnityEngine.NetworkReachability.NotReachable then
networkType = "NONE"
elseif CS.UnityEngine.Application.internetReachability == CS.UnityEngine.NetworkReachability.ReachableViaCarrierDataNetwork then
networkType = "DATA"
elseif CS.UnityEngine.Application.internetReachability == CS.UnityEngine.NetworkReachability.ReachableViaLocalAreaNetwork then
networkType = "WIFI"
end
return networkType
end
return DeviceHelper