IOS and tvOS device info

From Qt Wiki
Jump to navigation Jump to search

General Information

All methods usage Objective-C code. You could use Objective-C in your application on C++. All you need it just add new class with header *.h and implementation file *.mm. Then add this files to you *.pro using special keywords:

OBJECTIVE_HEADERS += \
    Helpers/Apple/redminedevicehelper.h

OBJECTIVE_SOURCES += \
    Helpers/Apple/redminedevicehelper.mm

Also you need to use frameworks for get access to basic Objective-C classes and methods:

  • UIKit
    #import <UIKit/UIKit.h>
    
  • Foundation
    #import <Foundation/Foundation.h>
    

In *.pro file you need add this frameworks as a library:

LIBS += -framework Foundation -framework CoreFoundation -framework UIKit


Methods

Device Type

If you need detect your iOS or tvOS device (iPhone, iPad, or Apple TV) in your application you can use code bellow:

BOOL isPhone = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone);
BOOL isPad = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
BOOL isAppleTV = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomTV);

Device model name

Name of device:

QString model = QString::fromNSString([[UIDevice currentDevice] model]);

Device OS Version

Name of device OS version (although you should use QOperatingSystemVersion instead of this method):

QString model = QString::fromNSString([[UIDevice currentDevice] systemVersion]);

Device scale factor and retina detection

//Device scale factor
float scale = (float)([UIScreen mainScreen].scale);

//Type of device display
bool isRetina = ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0)) ? true : false;

Device UUID

QString uuid = QString::fromNSString( [[[UIDevice currentDevice] identifierForVendor] UUIDString]);


Links

  1. For more information about methods you can fins in official documentation and UIDievice class reference on developer apple website.
  2. More hardware information you could find here and here.