IOS and tvOS device info

From Qt Wiki
Revision as of 15:48, 21 November 2015 by Shav (talk | contribs) (create new page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Get device information

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/iOS/redminedevicehelper.h

OBJECTIVE_SOURCES += \
    Helpers/iOS/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 device (iPhone or iPad) in your application you can use code bellow:

BOOL isPhone = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone);

Device model name

Name of device:

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

Device OS Version

Name of device OS version:

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.