获取iOS设备deviceModel

2022-01-07  本文已影响0人  tom__zhu
+ (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

上一篇下一篇

猜你喜欢

热点阅读