美文网首页
获取iOS设备deviceModel

获取iOS设备deviceModel

作者: tom__zhu | 来源:发表于2022-01-07 11:14 被阅读0次
    + (NSString*)deviceModel
    {
        NSString* machine = nil;
    #if TARGET_IPHONE_SIMULATOR
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
            machine = @"iPhone4,1";
        else machine = @"iPad3,1";
    #else
        
        /* set 'oldp' parameter to NULL to get the size of the data
         * returned so we can allocate appropriate amount of space
         */
        size_t size;
        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
        if (!size) return nil;
        
        // allocate the space to store name
        char* name = malloc(size);
        if (name)
        {
            // get the platform name
            sysctlbyname("hw.machine", name, &size, NULL, 0);
        
            // place name into a string
            machine = [NSString stringWithUTF8String:name];
        
            // exit it
            free(name);
        }
    #endif
        
        // ok?
        return machine;
    }
    
    sysctlbyname

    Models

    相关文章

      网友评论

          本文标题:获取iOS设备deviceModel

          本文链接:https://www.haomeiwen.com/subject/spljcrtx.html