Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS Device check for xcode 5
    text
    copied!<p>hope all are having a good day. I had implemented a device check files base on something I ran into here in stack overflow, i haven't been able to find the original post to past it here. If i happen to come across, I will reference it.</p> <p>This used to work great on the previous xcode 4.x but for xcode 5 I get this error.</p> <p>Expected method to read dictionary element not found on object of type 'NSDictionary *' NSString *deviceName = commonNamesDictionary[machineName];</p> <p>I manage to find this but it was for iOS 5 to iOS6 <a href="https://stackoverflow.com/questions/11658669/how-to-enable-the-new-objective-c-object-literals-on-ios">How to enable the new Objective-C object literals on iOS?</a> </p> <p>The code implemented is as follows. Obviously this was until iphone 5 not sure how to add the new phone archs.</p> <p>.h implementation</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;sys/utsname.h&gt; //to check if its a iphone 4s or iphone 5 @interface deviceCheck : NSObject +(NSString*)deviceModelName; @end </code></pre> <p>.m implementation</p> <pre><code>#import "deviceCheck.h" @implementation deviceCheck * device checking method to tell the difference between devices */ +(NSString*)deviceModelName { struct utsname systemInfo; uname(&amp;systemInfo); NSString *machineName = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; NSDictionary *commonNamesDictionary = @{ @"i386": @"iPhone Simulator", @"x86_64": @"iPad Simulator", @"iPhone1,1": @"iPhone", @"iPhone1,2": @"iPhone 3G", @"iPhone2,1": @"iPhone 3GS", @"iPhone3,1": @"iPhone 4", @"iPhone4,1": @"iPhone 4S", @"iPhone5,1": @"iPhone 5(GSM)", @"iPhone5,2": @"iPhone 5(GSM+CDMA)", @"iPad1,1": @"iPad", @"iPad2,1": @"iPad 2(WiFi)", @"iPad2,2": @"iPad 2(GSM)", @"iPad2,3": @"iPad 2(CDMA)", @"iPad2,4": @"iPad 2(WiFi Rev A)", @"iPad2,5": @"iPad Mini(WiFi)", @"iPad2,6": @"iPad Mini(GSM)", @"iPad2,7": @"iPad Mini(GSM+CDMA)", @"iPad3,1": @"iPad 3(WiFi)", @"iPad3,2": @"iPad 3(GSM+CDMA)", @"iPad3,3": @"iPad 3(GSM)", @"iPad3,4": @"iPad 4(WiFi)", @"iPad3,5": @"iPad 4(GSM)", @"iPad3,6": @"iPad 4(GSM+CDMA)", @"iPod1,1": @"iPod 1st Gen", @"iPod2,1": @"iPod 2nd Gen", @"iPod3,1": @"iPod 3rd Gen", @"iPod4,1": @"iPod 4th Gen", @"iPod5,1": @"iPod 5th Gen", }; NSString *deviceName = commonNamesDictionary[machineName]; // &lt;-- here is the issue if (deviceName == nil) { deviceName = machineName; } return deviceName; } @end </code></pre> <p>Anyone else has come across this issue?</p> <p>In advance thanks for your help on this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload