Determine device (iPhone, iPod Touch) with iOS

后端 未结 30 1782
礼貌的吻别
礼貌的吻别 2020-11-21 11:29

Is there a way to determine the device running an application. I want to distinguish between iPhone and iPod Touch, if possible.

30条回答
  •  既然无缘
    2020-11-21 11:53

    Adding to Arash's code, I don't care for my app what model I'm using, I just want to know what kind of device, so, I can test as follows:

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
            {
                NSLog(@"I'm definitely an iPad");
        } else {
        NSString *deviceType = [UIDevice currentDevice].model;
                    if([deviceType rangeOfString:@"iPhone"].location!=NSNotFound)
                    {
                        NSLog(@"I must be an iPhone");
    
                    } else {
                        NSLog(@"I think I'm an iPod");
    
                    }
    }
    

提交回复
热议问题