Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:35:50+00:00 2026-06-11T03:35:50+00:00

The code below is supposed to display the model/device name of the device running

  • 0

The code below is supposed to display the model/device name of the device running the app. For example, if the app was running on a 1st gen iPod, I want it to display “iPod1,1”. When I run the application, the label is empty. What am I doing wrong?

#import "ViewController.h"
#include <sys/types.h>
#include <sys/sysctl.h>

@interface ViewController ()

@end

@implementation ViewController
@synthesize label;

- (void)viewDidLoad
{
    label.text = [self platformString];
    [self platformCapabilities];

    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (NSString *) platform
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding: NSUTF8StringEncoding];
free(machine);
return platform;
}

- (int) platformType
{
NSString *platform = [self platform];
if ([platform isEqualToString:@"iPhone1,1"]) return UIDevice1GiPhone;
if ([platform isEqualToString:@"iPhone1,2"]) return UIDevice3GiPhone;
if ([platform isEqualToString:@"iPod1,1"])   return UIDevice1GiPod;
if ([platform isEqualToString:@"iPod2,1"])   return UIDevice2GiPod;
if ([platform hasPrefix:@"iPhone"]) return UIDeviceUnknowniPhone;
if ([platform hasPrefix:@"iPod"]) return UIDeviceUnknowniPod;
return UIDeviceUnknown;
}

- (NSString *) platformString
{
switch ([self platformType])
{
    case UIDevice1GiPhone: return IPHONE_1G_NAMESTRING;
    case UIDevice3GiPhone: return IPHONE_3G_NAMESTRING;
    case UIDeviceUnknowniPhone: return IPHONE_UNKNOWN_NAMESTRING;

    case UIDevice1GiPod: return IPOD_1G_NAMESTRING;
    case UIDevice2GiPod: return IPOD_2G_NAMESTRING;
    case UIDeviceUnknowniPod: return IPOD_UNKNOWN_NAMESTRING;

    default: return nil;
}
}

- (int) platformCapabilities
{
switch ([self platformType])
{
    case UIDevice1GiPhone: return UIDeviceBuiltInSpeaker | UIDeviceBuiltInCamera | UIDeviceBuiltInMicrophone | UIDeviceSupportsExternalMicrophone | UIDeviceSupportsTelephony | UIDeviceSupportsVibration;
    case UIDevice3GiPhone: return UIDeviceSupportsGPS | UIDeviceBuiltInSpeaker | UIDeviceBuiltInCamera | UIDeviceBuiltInMicrophone | UIDeviceSupportsExternalMicrophone | UIDeviceSupportsTelephony | UIDeviceSupportsVibration;
    case UIDeviceUnknowniPhone: return UIDeviceBuiltInSpeaker | UIDeviceBuiltInCamera | UIDeviceBuiltInMicrophone | UIDeviceSupportsExternalMicrophone | UIDeviceSupportsTelephony | UIDeviceSupportsVibration;

    case UIDevice1GiPod: return 0;
    case UIDevice2GiPod: return UIDeviceBuiltInSpeaker | UIDeviceBuiltInMicrophone | UIDeviceSupportsExternalMicrophone;
    case UIDeviceUnknowniPod: return 0;

    default: return 0;
}
}
@end

Also, how could I extend this code to recognize 3rd gen iPods, 4th gen iPods, etc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:35:52+00:00Added an answer on June 11, 2026 at 3:35 am

    You must be hitting your nil case. Did you try stepping into the platform method to see what it returns and if that matches any of your cases?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My code below is supposed to display each question ($_POST[questionText]). For each question, it
my code below is supposed to display N lines per inch. instead i get
Every time I run the code below it is supposed to come up with
Suppose I have an XSD file having below lines of code; <xsd:simpleType name=test> <xsd:restriction
Ok another question in VHDL. Below is my code. Suppose that I want my
I have a php code below where it is suppose to display my buttons,
The code below is supposed to prompt the user, step-by-step, for information. Currently, however,
I'm having a (probably super simple) issue. The code below is supposed to _POST
I have the code below which is supposed to check the database for entries
I suppose button should has Close title in the code below, but it has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.