Convert Figma logo to code with AI

lmirosevic logoGBDeviceInfo

Detects the hardware, software and display of the current iOS or Mac OS X device at runtime.

1,139
191
1,139
6

Top Related Projects

DeviceKit is a value-type replacement of UIDevice.

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.

1,681

Light weight tool for detecting the current device and screen size written in swift.

Quick Overview

GBDeviceInfo is a lightweight Objective-C library for detecting the hardware, software, and display characteristics of iOS, macOS, and tvOS devices. It provides detailed information about the device model, OS version, screen size, and other hardware specifications, making it useful for developers who need to tailor their apps for specific device capabilities.

Pros

  • Comprehensive device information for iOS, macOS, and tvOS platforms
  • Easy to integrate and use in Objective-C and Swift projects
  • Regularly updated to support new device models and OS versions
  • Lightweight and efficient, with minimal impact on app performance

Cons

  • Limited to Apple platforms (iOS, macOS, tvOS)
  • May require frequent updates to stay current with new device releases
  • Some advanced features may require additional setup or permissions

Code Examples

  1. Getting basic device information:
GBDeviceInfo *deviceInfo = [GBDeviceInfo deviceInfo];
NSLog(@"Device model: %@", deviceInfo.modelString);
NSLog(@"OS version: %@", deviceInfo.osVersion);
NSLog(@"CPU frequency: %.2f GHz", deviceInfo.cpuFrequency);
  1. Checking for specific device capabilities:
GBDeviceInfo *deviceInfo = [GBDeviceInfo deviceInfo];
if (deviceInfo.family == GBDeviceFamilyiPad && deviceInfo.display >= GBDeviceDisplayiPadRetina) {
    NSLog(@"This is a Retina iPad");
}
  1. Determining the device generation:
GBDeviceInfo *deviceInfo = [GBDeviceInfo deviceInfo];
switch (deviceInfo.generation) {
    case GBDeviceGenerationiPhone6S:
        NSLog(@"This is an iPhone 6S");
        break;
    case GBDeviceGenerationiPhoneX:
        NSLog(@"This is an iPhone X");
        break;
    default:
        NSLog(@"This is another iPhone model");
}

Getting Started

  1. Add GBDeviceInfo to your project using CocoaPods:
pod 'GBDeviceInfo'
  1. Import the header in your Objective-C file:
#import <GBDeviceInfo/GBDeviceInfo.h>
  1. For Swift projects, add the following to your bridging header:
#import <GBDeviceInfo/GBDeviceInfo.h>
  1. Start using GBDeviceInfo in your code:
GBDeviceInfo *deviceInfo = [GBDeviceInfo deviceInfo];
NSLog(@"Device model: %@", deviceInfo.modelString);

Competitor Comparisons

DeviceKit is a value-type replacement of UIDevice.

Pros of DeviceKit

  • Written in Swift, providing better integration with modern iOS development
  • More comprehensive device detection, including newer models and detailed specifications
  • Active development and frequent updates

Cons of DeviceKit

  • Larger codebase, potentially increasing app size
  • May have a steeper learning curve for developers new to Swift

Code Comparison

DeviceKit:

let device = Device.current
if device.isPad {
    print("Running on iPad")
}

GBDeviceInfo:

GBDeviceInfo *deviceInfo = [GBDeviceInfo deviceInfo];
if (deviceInfo.family == GBDeviceFamilyiPad) {
    NSLog(@"Running on iPad");
}

Key Differences

  • DeviceKit uses Swift's enum-based approach for device identification, while GBDeviceInfo relies on Objective-C constants
  • DeviceKit provides more granular device information and capabilities
  • GBDeviceInfo offers cross-platform support (iOS, macOS, tvOS), while DeviceKit focuses primarily on iOS devices

Conclusion

DeviceKit is better suited for modern Swift-based iOS projects, offering more detailed device information. GBDeviceInfo may be preferable for projects requiring cross-platform support or those still using Objective-C.

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.

Pros of device-detector

  • Multi-platform support (PHP, JavaScript, Java, Python, etc.)
  • Extensive device database with regular updates
  • Capable of detecting bots and crawlers

Cons of device-detector

  • Requires more setup and configuration
  • Potentially slower performance due to extensive database lookups
  • Larger footprint and dependencies

Code Comparison

GBDeviceInfo:

GBDeviceInfo *deviceInfo = [GBDeviceInfo deviceInfo];
NSLog(@"Device model: %@", deviceInfo.modelString);
NSLog(@"iOS version: %@", deviceInfo.osVersion);

device-detector:

$userAgent = $_SERVER['HTTP_USER_AGENT'];
$dd = new DeviceDetector($userAgent);
$dd->parse();
$deviceInfo = $dd->getDeviceName();
$osInfo = $dd->getOs();

Summary

GBDeviceInfo is a lightweight, iOS-focused library for device information retrieval, while device-detector is a more comprehensive, multi-platform solution with broader device support and bot detection capabilities. GBDeviceInfo offers simpler implementation and potentially better performance for iOS-specific use cases, whereas device-detector provides more extensive device information across various platforms at the cost of increased complexity and resource usage.

1,681

Light weight tool for detecting the current device and screen size written in swift.

Pros of Device

  • Simpler API with fewer methods, making it easier to use for basic device information
  • Includes a method to get the device name set by the user
  • Lightweight and focused specifically on iOS devices

Cons of Device

  • Less comprehensive device information compared to GBDeviceInfo
  • Limited support for other platforms (e.g., macOS, watchOS)
  • Less frequently updated, potentially missing information on newer devices

Code Comparison

Device:

let device = Device()
let deviceName = device.name
let deviceModel = device.type

GBDeviceInfo:

GBDeviceInfo *deviceInfo = [GBDeviceInfo deviceInfo];
NSString *deviceModel = [deviceInfo.modelString stringByReplacingOccurrencesOfString:@"Simulator" withString:@""];
BOOL isTablet = deviceInfo.isTablet;

Both libraries provide easy access to device information, but GBDeviceInfo offers more detailed and extensive data across multiple platforms. Device focuses on simplicity and ease of use for iOS-specific information, while GBDeviceInfo provides a more comprehensive solution for developers needing detailed device data across various Apple platforms.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

GBDeviceInfo logo

Detects the hardware, software and display of the current iOS or Mac OS X device at runtime.

Version License

iOS

Simple usage (examples on iPhone 6 running iOS 8.1.3):

[[GBDeviceInfo deviceInfo] isOperatingSystemAtLeastVersion:@"8.0"]; // #> YES

[GBDeviceInfo deviceInfo].isJailbroken;                             // #> NO

[GBDeviceInfo deviceInfo].model;                                    // #> GBDeviceModeliPhone6
[GBDeviceInfo deviceInfo].family;                                   // #> GBDeviceFamilyiPad

[GBDeviceInfo deviceInfo].modelString;                              // #> @"iPhone 6"
[GBDeviceInfo deviceInfo].osVersion.major;                          // #> 8
[GBDeviceInfo deviceInfo].osVersion.minor;                          // #> 1

[GBDeviceInfo deviceInfo].displayInfo.pixelsPerInch;                // #> 326

You can also reuse the returned object to save some typing. First assign the object to some variable:

GBDeviceInfo *deviceInfo = [GBDeviceInfo deviceInfo];

Then get whatever you like from the object:

//Model numbers
NSLog(@"Major device ver: %d", deviceInfo.deviceVersion.major);     // Major device ver: 7
NSLog(@"Major device ver: %d", deviceInfo.deviceVersion.minor);     // Minor device ver: 2


//Specific model
if (deviceInfo.model == GBDeviceModeliPhone6) {
    NSLog(@"It's a 6");                                             // It's a 6
}

//Family of device
if (deviceInfo.family != GBDeviceFamilyiPad) {
    NSLog(@"It's not an iPad");                                     // It's not an iPad
}

//Screen type
if (deviceInfo.display == GBDeviceDisplayiPhone4p7Inch) {
    NSLog(@"4.7 Inch display");                                     // 4.7 Inch display
}

//iOS Version
if (deviceInfo.majoriOSVersion >= 6) {
    NSLog(@"We've got iOS 6+");                                     // We've got iOS 6+
}

//Raw systemInfo string
NSLog(@"systemInfo: %@", deviceInfo.rawSystemInfoString);           // systemInfo: iPhone7,2

Don't forget to import header.

#import <GBDeviceInfo/GBDeviceInfo.h>

If you want to use the isJailbroken property, make sure you first add the Jailbreak subspec to your project's Podfile, e.g.:

pod 'GBDeviceInfo', '~> 6.0'
pod 'GBDeviceInfo/Jailbreak', '~> 6.0'

Missing a property you need? Submit a Pull Request or contact sales@goonbee.com!

OS X

Simple usage (examples on a Mac Pro with an Ivy Bridge 3770K processor running 10.8.2):

[[GBDeviceInfo deviceInfo] isOperatingSystemAtLeastVersion:@"10.8"]; // #> YES

[GBDeviceInfo deviceInfo].osVersion.major;                           // #> 10
[GBDeviceInfo deviceInfo].osVersion.minor;                           // #> 8
[GBDeviceInfo deviceInfo].family == GBDeviceFamilyMacPro;            // #> YES
[GBDeviceInfo deviceInfo].isMacAppStoreAvailable;                    // #> YES
[GBDeviceInfo deviceInfo].isIAPAvailable;                            // #> YES

You can also reuse the returned object to save some typing. First assign the object to some variable:

GBDeviceInfo *deviceInfo = [GBDeviceInfo deviceInfo];

Then get whatever you like from the object:

GBDeviceInfo *deviceInfo = [GBDeviceInfo deviceInfo];

//OS X Version
if (deviceInfo.osVersion.minor >= 8) {
    NSLog(@"It's OS X 10.8+ (Mountain Lion)");                     // It's OS X 10.8+ (Mountain Lion)
}
if (deviceInfo.osVersion.patch == 2) {
    NSLog(@"Must be running x.x.2");                               // Must be running x.x.2
}

//App Store stuff
if (deviceInfo.isMacAppStoreAvailable) {
    NSLog(@"App store is available.");                             // App store is available
}
if (deviceInfo.isIAPAvailable) {
    NSLog(@"...and so are IAPs");                                  // ...and so are IAPs
}

//Hardware stuff
NSLog(@"SystemInfo: %@", deviceInfo.rawSystemInfoString);          // SystemInfo: MacPro3,1
NSLog(@"Major device ver: %d", deviceInfo.deviceVersion.major);    // Major device ver: 3
NSLog(@"Minor device ver: %d", deviceInfo.deviceVersion.minor);    // Minor device ver: 1
NSLog(@"Node name: %@", deviceInfo.nodeName);                      // Node name: MyMac.local
NSLog(@"RAM: %.3f GB", deviceInfo.physicalMemory);                 // RAM: 16.000 GB
NSLog(@"CPU freq: %.3f GHz", deviceInfo.cpu.frequency);            // CPU freq: 3.500 GHz
NSLog(@"Number of cores: %d", deviceInfo.cpu.numberOfCores);       // Number of cores: 8
NSLog(@"L2 Cache size: %.0f KB", deviceInfo.cpu.l2CacheSize);      // L2 Cache size: 256 KB

//Endianness
if (deviceInfo.byteOrder == GBByteOrderLittleEndian) {
    NSLog(@"Little Endian");                                       // Little Endian
}

//Family of device
if (deviceInfo.family != GBDeviceFamilyMacBookAir) {
    NSLog(@"It's not a Macbook Air");                              // It's not a Macbook Air
}

//Screen resolution
if (deviceInfo.screenResolution.width == 1920 && deviceInfo.screenResolution.height == 1200) {
    NSLog(@"Resolution: 1920x1200");                              // Resolution: 1920x1200
}

Don't forget to import framework:

#import <GBDeviceInfo/GBDeviceInfo.h>

Missing a property you need? Submit a Pull Request or contact sales@goonbee.com!

iOS Device support

  • iPhone1
  • iPhone3G
  • iPhone3GS
  • iPhone4
  • iPhone4S
  • iPhone5
  • iPhone5C
  • iPhone5S
  • iPhone6
  • iPhone6Plus
  • iPhone6S
  • iPhone6SPlus
  • iPhone7
  • iPhone7Plus
  • iPhone8
  • iPhone8Plus
  • iPhoneSE
  • iPhoneSE2
  • iPhoneSE3
  • iPhoneX
  • iPhoneXR
  • iPhoneXS
  • iPhoneXSMax
  • iPhone11
  • iPhone11Pro
  • iPhone11ProMax
  • iPhone12Mini
  • iPhone12
  • iPhone12Pro
  • iPhone12ProMax
  • iPhone13Mini
  • iPhone13
  • iPhone13Pro
  • iPhone13ProMax
  • iPhone14
  • iPhone14Plus
  • iPhone14Pro
  • iPhone14ProMax
  • iPhone15
  • iPhone15Plus
  • iPhone15Pro
  • iPhone15ProMax
  • iPad1
  • iPad2
  • iPad3
  • iPad4
  • iPad5
  • iPad6
  • iPad7
  • iPad8
  • iPad9
  • iPad10
  • iPadMini1
  • iPadMini2
  • iPadMini3
  • iPadMini4
  • iPadMini5
  • iPadMini6
  • iPadAir1
  • iPadAir2
  • iPadAir3
  • iPadAir4
  • iPadAir5
  • iPadPro9p7Inch
  • iPadPro10p5Inch
  • iPadPro12p9Inch
  • iPadPro12p9Inch2
  • iPadPro11Inch
  • iPadPro11Inch2
  • iPadPro12p9Inch3
  • iPadPro12p9Inch4
  • iPadPro11Inch3
  • iPadPro12p9Inch5
  • iPadPro11Inch4
  • iPadPro12p9Inch6
  • iPod1
  • iPod2
  • iPod3
  • iPod4
  • iPod5
  • iPod6
  • iPod7
  • iPhone Simulator
  • iPad Simulator

OS X Device family support

  • iMac
  • iMacPro
  • MacMini
  • MacStudio
  • MacPro
  • MacBook
  • MacBookAir
  • MacBookPro
  • Xserve

Author

Luka Mirosevic (@lmirosevic)

Enterprise

Premium support, integration, use-case adaptations and consulting available. Contact sales@goonbee.com.

Copyright & License

Copyright 2015 Goonbee

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.