获取安装游戏应用设备信息(swift)

来源:互联网 发布:中科大软件学院排名 编辑:程序博客网 时间:2024/06/05 10:21

有时候我们做游戏,会针对ipad或者iphone做一些特殊的设置,让其游戏更好的适应不同的设备,这样,我们就需要在代码里分辨和判断打开游戏的是什么设备,好调用相应的逻辑处理。好吧,这个没什么大问题,直接贴代码吧

//分辨不同设备

        if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Phone{

          print("iphone")

        }

       

        if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad{

        print("ipad")

           

        }



如果你想要获得当前设备更多的信息,主要是通过返回的UIDevice实例,用他的属性获得更多设备信息

UIDevice类的部分属性

public var name: String { get } // e.g. "My iPhone"

    public var model: String { get } // e.g. @"iPhone", @"iPod touch"

    public var localizedModel: String { get } // localized version of model

    public var systemName: String { get } // e.g. @"iOS"

    public var systemVersion: String { get } // e.g. @"4.0"

    public var orientation: UIDeviceOrientation { get } // return current device orientation.  this will return UIDeviceOrientationUnknown unless device orientation notifications are being generated.

   

    @available(iOS 6.0, *)

    public var identifierForVendor: NSUUID? { get } // a UUID that may be used to uniquely identify the device, same across apps from a single vendor.

   

具体使用方法:

//获取当前设备

        let device = UIDevice.currentDevice()

        print(device.name)

        print(device.model)

        print(device.systemName)

        print(device.systemVersion)



 

 

 


0 0
原创粉丝点击