IOS and tvOS device info: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(create new page)
 
(Gather iOS pages into a category)
Line 1: Line 1:
= Get device information =
[[Category:iOS]]
== General 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:
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:

Revision as of 16:03, 25 November 2016

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.