Determine device (iPhone, iPod Touch) with iOS

后端 未结 30 1753
礼貌的吻别
礼貌的吻别 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 12:03

    I know an answer has been ticked already, but for future reference, you could always use the device screen size to figure out which device it is like so:

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    
        CGSize result = [[UIScreen mainScreen] bounds].size;
    
        if (result.height == 480) {
            // 3.5 inch display - iPhone 4S and below
            NSLog(@"Device is an iPhone 4S or below");
        }
    
        else if (result.height == 568) {
            // 4 inch display - iPhone 5
            NSLog(@"Device is an iPhone 5/S/C");
        }
    
        else if (result.height == 667) {
            // 4.7 inch display - iPhone 6
            NSLog(@"Device is an iPhone 6");
        }
    
        else if (result.height == 736) {
            // 5.5 inch display - iPhone 6 Plus
            NSLog(@"Device is an iPhone 6 Plus");
        }
    } 
    
    else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
           // iPad 9.7 or 7.9 inch display.
           NSLog(@"Device is an iPad.");
    }
    

提交回复
热议问题