开发手册API方式接入事件埋点上报设备信息参数指南
ℹ️

设备信息参数说明

我们需要获取一些设备信息用于事件埋点接入指南参数上报。 以下是设备信息获取参考:

Android信息获取参考

native_msg
调用:clipboard.getPrimaryClip().getItemAt(0).getText()
deep_link_url
监听打开链接获取:activity.getIntent().getData().toString()
os
固定:Android
os_version
调用:Build.VERSION.RELEASE
device_model
调用:Build.MODEL
device_id
调用:移动设备标识,只要是唯一设备标识即可
brand
调用:Build.BRAND
country
调用:Locale.getDefault().country
language
调用:Locale.getDefault().language
screen_height
调用:application.getResources().getDisplayMetrics().heightPixels
screen_width
调用:application.getResources().getDisplayMetrics().widthPixels
ipv4
APP上报:该参数赋值""
服务端上报:服务端获取APP的ip赋值到这个参数

iOS信息获取参考

native_msg
调用:UIPasteboard.general.string
deep_link_url
监听打开链接获取:.onOpenURL { url in }
os
调用:UIDevice.current.systemName
os_version
调用:UIDevice.current.systemVersion
device_model
调用:UIDevice.current.model
device_id
调用:UIDevice.current.identifierForVendor?.uuidStringASIdentifierManager.shared().advertisingIdentifier.uuidString
brand
固定iPhone
country
调用:Locale.current.region?.identifier.uppercased()
language
调用:Locale.current.languageCode?.lowercased()
screen_height
调用:Int32(UIScreen.main.bounds.size.height * UIScreen.main.scale)
screen_width
调用:Int32(UIScreen.main.bounds.size.width * UIScreen.main.scale)
ipv4
APP上报:该参数赋值""
服务端上报:服务端获取APP的ip赋值到这个参数
local_ip

var ipv4: String? = ""
var localIP: String? = ""
var ifaddr: UnsafeMutablePointer<ifaddrs>? = nil
if getifaddrs(&ifaddr) == 0 {
    var ptr = ifaddr
    while ptr != nil {
        defer { ptr = ptr?.pointee.ifa_next }
 
        let interface = ptr?.pointee
        let addrFamily = interface?.ifa_addr.pointee.sa_family
        if addrFamily == UInt8(AF_INET) {
            let name: String = String(cString: (interface!.ifa_name))
            if  name == "en0" || name == "pdp_ip0" {
                var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
                getnameinfo(interface?.ifa_addr, socklen_t((interface?.ifa_addr.pointee.sa_len)!), &hostname, socklen_t(hostname.count), nil, socklen_t(0), NI_NUMERICHOST)
                 
                if  name == "en0" {
                    ipv4 = String(cString: hostname)
                } else {
                    localIP = localIP == "" ? String(cString: hostname) : localIP
                }
            }
        }
    }
    freeifaddrs(ifaddr)
}