0

Say if I have 3 animation files for a size for iPhone 5s, iPhone 6 and iPhone 6 Plus. What about ipad?

For the same view controller, how should I use these respective files for different iPhone sizes. Here's a specific example:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@”iphone5s” ofType:@”gif”];

but what if I want to load for iPhone 6, iPhone 6 plus called iPhone6.gif, iPhone6Plus.gif etc

I am using Objective-C.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
VideoGamingIOs
  • 119
  • 1
  • 9

3 Answers3

2

You can use SDVersion to detect the current device information . SDVersion is :

Objective-C library for detecting the running device's model and screen size

So you can use it to get device model ,device screen size,device name,and iOS Version as follow:

  // Check for device model
  if ([SDVersion deviceVersion] == iPhone6)
       NSLog(@"You got the iPhone 6. Sweet !");
  else if ([SDVersion deviceVersion] == iPhone6Plus)
       NSLog(@"iPhone 6 Plus? Bigger is better!");
  else if ([SDVersion deviceVersion] == iPadAir2)
       NSLog(@"You own an iPad Air 2 !");

  // Check for device screen size
  if ([SDVersion deviceSize] == iPhone4inch)
       NSLog(@"Your screen is 4 inches");

  // Get device name
  NSLog(@"%@", stringFromDeviceVersion([SDVersion deviceName]));
  /* e.g: Outputs 'iPhone 6 Plus' */

  // Check for iOS Version
  if (iOSVersionGreaterThanOrEqual(@"8"))
       NSLog(@"You are running iOS 8 or above!");

In your situation , you can:

NSString *name;
DeviceSize size = [SDVersion deviceSize];

if (size == iPhone35inch)
    name = @"iPhone4";
else if(size == iPhone4inch)
    name = @"iPhone5";
else if(size == iPhone47inch)
    name = @"iPhone6";
else if(size == iPhone55inch)
    name = @"iPhone6Plus";
else
    name = @"iPad";


NSString *filePath = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
Community
  • 1
  • 1
monjer
  • 2,809
  • 2
  • 21
  • 31
1

Try using specific image file names with appropriate naming conventions. Like,

     - fileName.png -> iPhone (non-retina/fallback)
     - fileName@2x.png -> iPhone (retina)
     - fileName@3x.png -> iPhone 6 Plus (retina)
     - fileName~ipad.png -> iPad (non-retina)
     - fileName@2x~ipad.png -> iPad (retina)

So, in code we can use:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@”fileName” ofType:@”png”];

And internally OS will detect the device version and pick the respective image to showcase.

I have used this using storyboard image assigning, I have not tried with codebase, but you can give a try.

Hope this helps.

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Mrunal
  • 13,982
  • 6
  • 52
  • 96
  • Thank you! I will see if it works, because the other problem is, say if I want the size of the video to be increased for iPhone 6 plus, do I have to use idiom for that. I think I will keep it constant. – VideoGamingIOs Dec 03 '14 at 09:06
  • I don't think you would require any naming convention for video file. It should be one file which works for all devices. Only thing is your video should be H.264 video, up to 1.5 Mbps. Still am not sure about video, but I think it should work. – Mrunal Dec 03 '14 at 09:16
0

You can use uname from sys/utsname.h for getting device model.

Take a look at this

Community
  • 1
  • 1
Sandr
  • 189
  • 9