iPhone : How to check device using MACRO?

I want to check whether the device is iPhone or iPad using the macro.

I have a file Constant.h where I have given values using #define.

Now, I want to check device using #ifdef #endif.

Follwing method can be possible only in the .m file.

But I have only one .h only.

- (BOOL) isPad{ 
   #ifdef UI_USER_INTERFACE_IDIOM
        return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
   #else
       return NO;
   #endif
}

So above method is not useful for me ?

Is there any way to do this ? Or any other way?

Answers


You can't check it by macro, because macro is expanded during compilation. So you need to know device type at compile time.

If you want to support both devices at runtime, you need to check device type and use appropriate set of constants.


I have simple answer to this question.

#define isiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? YES : NO)

This will returns 1 if device is iPad and 0 if device is iPod or iPhone.


Need Your Help

How to use timer's OSTmrCreate to implement task scheduling with MicroC/OS II?

c scheduled-tasks rtos nios microc

I got 2 tasks in MicroC to simulate a moving vehicle: ControlTask and VehicleTask. Now my project should replace the context switch with a timer for more appropriate timing but I can't seem to get it

Compare() method, Parent and Children objects sorting not perfect

c# arrays compare icomparable

I have this homework. And I am beginner C# program, and now learn the C# and Java

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.