现在的位置: 首页 > 综合 > 正文

iOS 获得设备名称

2017年10月04日 ⁄ 综合 ⁄ 共 1285字 ⁄ 字号 评论关闭

//获得设备类型

std::string   getDeviceType(int  & bigVer,  
int  & littleVer)

{

    /*

     * desc: get ios device type

     *

     * iPhone1,1   iPhone

     * iPhone1,2   iPhone 3G

     * iPhone2,1   iPhone 3GS

     * iPhone3,1   iPhone 4

     * iPhone3,3   iPhone 4 (Verizon)

     * iPhone3,3   iPhone 4 (CDMA)

     * iPhone4,1   iPhone 4S

     * iPhone5,1   iPhone 5 (not sure)

     *

     * iPod1,1     iPod Touch1

     * iPod2,1     iPod Touch2

     * iPod3,1     iPod Touch3

     * iPod4,1     iPod Touch4

     * iPod5,1     iPod Touch5 (not sure)

     *

     * iPad1,1     iPad1

     * iPad2,1     iPad2 (Wifi)

     * iPad2,2     iPad2 (3G GSM)

     * iPad2,3     iPad2 (3G CDMA)

     * iPad2,5     iPad Mini (may be)

     * iPad2,6     iPad Mini (may be)

     * iPad3,1     iPad3 (Wifi)

     * iPad3,2     iPad3 (4G)

     * iPad3,3     iPad3 (4G)

     * iPad3,6     iPad4 (may be)

     *  

     * i386        Simulator  

     * x86_64      Simulator 

     *  

     * AppleTV2,1 AppleTV(2G) 

     */

    struct utsname systemInfo;

    uname(&systemInfo);

    NSString *machine = [NSString
stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];

    

    std::string   strMachineName = [machine 
UTF8String];

    

    string::size_type   findPos =  strMachineName.find(",");

    if (findPos !=  
string
::npos )

    {

        //iphone3,1

        

        string strHighVer =  strMachineName.substr(findPos -1, 1);

        bigVer = atoi(strHighVer.c_str() );

        

        

        string  strLowVer = strMachineName.substr(findPos +1,1);

        littleVer = atoi(strLowVer.c_str() );

    }

    

    

    return strMachineName;

}

抱歉!评论已关闭.