IOS and tvOS device info: Difference between revisions
Jump to navigation
Jump to search
(Gather iOS pages into a category) |
m (Jake Petroules moved page IOS device info to IOS and tvOS device info) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category:iOS]] | [[Category:iOS]] | ||
[[Category:tvOS]] | |||
== 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: | ||
<code>OBJECTIVE_HEADERS += \ | <code>OBJECTIVE_HEADERS += \ | ||
Helpers/ | Helpers/Apple/redminedevicehelper.h | ||
OBJECTIVE_SOURCES += \ | OBJECTIVE_SOURCES += \ | ||
Helpers/ | Helpers/Apple/redminedevicehelper.mm | ||
</code> | </code> | ||
Line 20: | Line 21: | ||
== Methods == | == Methods == | ||
=== Device Type === | === Device Type === | ||
If you need detect your iOS device (iPhone or | If you need detect your iOS or tvOS device (iPhone, iPad, or Apple TV) in your application you can use code bellow: | ||
<code>BOOL isPhone = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone);</code> | <code>BOOL isPhone = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone); | ||
BOOL isPad = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad); | |||
BOOL isAppleTV = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomTV);</code> | |||
=== Device model name === | === Device model name === | ||
Line 28: | Line 31: | ||
=== Device OS Version === | === Device OS Version === | ||
Name of device OS version: | Name of device OS version (although you should use QOperatingSystemVersion instead of this method): | ||
<code>QString model = QString::fromNSString([[UIDevice currentDevice] systemVersion]);</code> | <code>QString model = QString::fromNSString([[UIDevice currentDevice] systemVersion]);</code> | ||
Latest revision as of 20:36, 16 February 2017
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
- For more information about methods you can fins in official documentation and UIDievice class reference on developer apple website.
- More hardware information you could find here and here.