Just finished up my iPhone appln, now wants to use same appln for creating an iPad version. What i really want to do is to detect which on which device the app is running and accordingly pick UI at runtime. I get some code regarding which is my current device. Basically main idea behind is that is i don't want to write the server-client communication part again for separate ipad version. Ui is different hence I don't want to create a universal app for this.
My Prob: What settings should I do to make to work the application as described above. Currently when I run using iPhone Simulator, It says tht my current device is iPhone. But, when I changed my device to iPad Simulator and than run it back again, it convert that int iphone simulator.
Thanks.
you can check with this line:
NSString *model = [[NSString alloc]initWithString:[[UIDevice currentDevice] model]];
model value would be either iPhone or iPad
or you can go with [[UIDevice currentDevice] userInterfaceIdiom] and compare the values with
typedef enum {
UIUserInterfaceIdiomPhone,
UIUserInterfaceIdiomPad,
} UIUserInterfaceIdiom;
I have an opengl application that renders better in RetinaDisplay mode (double scale factor) and I noticed the iPad emulates an iPhone app with a low resolution screen (normal scale factor).
I want to double the scale factor when my iPhone app is run on an iPad, in order to benefit from Retina Display graphics. But it seems the iPad really well fakes being an iPhone (which would be perfect if only it was a Retina Display one...)
When I force the double scale, it works very well (at least in simulator, I do not have an iPad to test).
So I need a way to know if I am run on an iPad despite many things telling me it to be an old iPhone.
Or maybe I should not try to do that ?
If the app is an iPhone app running in the emulator mode on an iPad, it will have a userInterfaceIdiom of Phone, but a model type of iPad. You can check this with the following code:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
[[[UIDevice currentDevice] model] hasPrefix:#"iPad"]) {
// This app is an iPhone app running on an iPad
}
If you are looking to make custom code (most likely custom UI related methods) for the iPad only then you can use (as Apple directs) the UI_USER_INTERFACE_IDIOM() method that exists in iOS 3.2 and later
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// The device is an iPad running iPhone 3.2 or later.
}
else
{
// The device is an iPhone or iPod touch.
}
You can read more here http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BuildTimeConfiguration/BuildTimeConfiguration.html
This is the Apple recommended method
Look up in the documentation, UIDevice:
For instance something like:
NSString *system = [[UIDevice currentDevice] systemName];
Then by using [system isEqualToString:#"iPad"] whether its an ipad or not.
UIDevice is a very nice class, it also has stuff like multiTaskingSupported, systemVersion etc. gotta love UIKit ;)
i think it is that:
// Set hello to "Hello, <device or simulator>"!
if TARGET_IPHONE_SIMULATOR
NSString *hello = #"Hello, iOS Simulator!";
else
NSString *hello = #"Hello, iOS device!";
endif
the link apple doc
about
This actually will only tell you if
the app is being run in a simulated
environment, or on an actual device,
and has no influence on whether the
platform is iPad or iPhone.
In fact it says at compile time the target of the platform you are compiling for, thus before run you know and do the necessary for take care of something specific.
For example I have diferent URL for developing (running on simulator) and for production usage, so I do some like
#if TARGET_IPHONE_SIMULATOR
#define URL #"http://192.x.x.x/request"
#else
#define URL #"http://example.com/request"
#endif
you shouldn't be able to tell the difference, if its an iPhone app, then as far as it can tell it is running on an iPhone. if you want to target an iPad, then you need to build it for an iPad target.
I have iOS 4.0 on an iPod Touch 2nd Gen.
There's absolutely no multitasking working. Nothing goes to the background, and double-tapping the Home Button results in just nothing. I wanted to test my app against this new feature, but it appears that it doesn't work for iPod Touch devices?
Does that only work on the iPhone? Or is there some minor upgrade like 4.0.0.1 that enabled multitasking? Or must I enable that somewhere, manually?
Really strange. I do the exact same thing like the Apple guys do in the demo videos.
The documentation says:
The ability to run background tasks is not supported on all iPhone OS–based devices. If a device is not running iPhone OS 4 and later, or if the hardware is not capable of running applications in the background, the system reverts to the previously defined behavior for handling applications.
You can test if it's supported with the following code:
UIDevice * device = [ UIDevice currentDevice ];
BOOL backgroundSupported = NO;
if( [ device respondsToSelector: #selector( isMultitaskingSupported ) ] )
{
backgroundSupported = device.multitaskingSupported;
}
Multitasking only works on the 3GS iPhones and up. You are out of luck with your 2nd Gen iPod Touch (its like the iPhone 3G, sort of). Sorry.
EDIT: You would need a 3rd Gen iPod Touch, just to be clear.
You need a 3rd gen iPod Touch for that to work. I've run into the same issue.
According to this wikipedia article (see features section) multitasking is supported on 3rd gen iPods only
Apple's official ipsw's (iphone software) have disabled multitasking for ipt2g. If you jailbreak you can enable multitasking for your device but the performance will be poor.
Mutitasking is supported by 3 generation n 4g ... Iphones
I believe UILocalNotifications, part of the multitasking package, are supported on the 2G iPod Touch and the iPhone 3G.
So I'm currently using UI_USER_INTERFACE_IDIOM in conjunction with [[UIDevice currentDevice] model] to check if I'm on an iPhone, iPod or iPad. What I've found is that in the iPad simulator 3.2, UI_USER_INTERFACE_IDIOM still evaluates to UIUserInterfaceIdiomPhone (iPhone).
I'm wondering if this has something to do with my Targeted Device Family setting. I'm only targeting iPhone for my App (I don't want to make a universal app with scaling views). However, I support the 3.2 SDK so I still want users that have an iPad to be able to run my iPhone app.
Will UI_USER_INTERFACE_IDIOM evaluate correctly on the iPad even when I'm targeting iPhone?
UI_USER_INTERFACE_IDIOM does not check if the device is an iPhone or iPad. What it checks is whether the user interface is in iPhone mode (the 1x/2x thing) or iPad mode.
If an app isn't configured to target iPad, it will always return UIUserInterfaceIdiomPhone because the UI is an iPhone app. It is a feature by design.
And even if the app is configured to target iPhone only, the iPad should be able to run it without any problems as long as you use the methods as documented.
(If you need iPad-specific capabilities, do not check whether the device really is an iPad. Instead, check for individual capability.)
Best I can offer is that on the iPad simulator (3.2) while running in "iPhone" mode the
NSLog(#"model : %#", [UIDevice currentDevice].model);
returns
model : iPhone Simulator
(as a note: I am building for "iPhone" only and thus running in the iPhone experience on iPad. I have to assume the "model" name returned is affected by that)
As people have said, check the individual capability.
For making a call, do this
// Only show the button if its is a device capable of making calls
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"tel:"]]) {
self.Button.hidden = NO;
} else {
self.Button.hidden = YES;
}
I have heard of apps not working properly on the simulator but working properly on the actual iPhone device. Has anyone experienced an app that runs perfectly in the simulator but not on the actual iPhone device?
Filenames are case-sensitive on the iPhone, but not in the simulator.
So, for example, if you try to load an image with UIImage *iconImage = [UIImage imageNamed:"MyIcon.png"], but your resource is actually named "myicon.png", then it will work on the simulator, but not on the device.
If your app is graphics intensive, like say a game, the performance of the simulator DOES NOT resemble at all that of the hardware. Your application will probably be smooth and work great on the simulator, but on hardware it'll likely render at a crawl unless you know what your doing. You can easily go from 60fps to 3fps between Simulator and hardware.
The order in which function/constructor parameters are evaluated is different:
int i = 0;
int f() { return ++i; }
int a, b;
int test(int p1, int p2) {
a = p1;
b = p2;
}
test( f(), f() );
//simulator: a = 2, b = 1
//device: a = 1, b = 2
Trigonometry functions may return different results:
float a = cosf( 0.108271248639 );
printf("%.12f", a);
//simulator: 0.994144439697
//device: 0.994144380093
I know there are some differences in the OpenGL ES implementation between the device and the simulator. From what I understand this is mainly because of the graphics chip on the iPhone (PowerVR MBX) having vastly different capabilities than other mac machines. Many of the hardware limits are not enforced in the simulator, so it is entirely possible to get something running in the simulator that will totally crash on the device.
There are also some OpenGL ES extensions that are supported by the iPhone hardware that are not supported in the simulator. I believe the major one is PowerVR texture compression (PVRTC).
Another problem area can be memory footprint. Anecdotally, I have not seen the simulator automatically enforce the memory limitations of the device. Therefore, it is possible to have something that runs in the simulator fine, happily consuming copious amounts of RAM and never bothering to free any of it only to be swiftly terminated after a short continuance of such behaviour when running on a device.
There are certain bits of code that won't work on the simulator (using the iPhone Keychain, for example), but for almost all applications, the simulator will work exactly like the iPhone.
That said, there's absolutely no replacement for testing on a real device.
I had a problem running a relatively simple 1/30 sec timer to do updates for a game. It runs fine in the simulator, and freezes out input on the device.
Also note that you will be compiling against the OS X frameworks (where applicable) when building for the simulator so you could be using methods and classes that aren't available on the iPhone versions of the frameworks.
One example I can think of off the top of my head is NSPredicate. I was able to compile and run an app using NSPredicate in the simulator, but it wouldn't compile for the device since that class isn't available.
Fingertips are larger than the 1 pixel endpoint of a mouse cursor. To do proper, even minimal, usability testing you should deploy your App to a device.
If you enable GCC_ENABLE_FLOATING_POINT_LIBRARY_CALLS, your app will crash all over the place in the simulator but work on the iPhone.
Quartz graphics calls in the iPhone simulator are faster than Java2D calls on the same computer--wicked fast.
I've had issues in memory-hungry applications where the Simulator would work just fine (because it would assume the iPhone/iPod Touch's memory was all yours to play with), while the device would crash (because other apps had leaked and Apple background services had eaten up some memory) and I hadn't implemented proper memory management or a response to the didReceiveMemoryWarning selector.
One big thing that took me a while to spot was that the simulator does not support device tokens, so any code that involves those will not run on the simulator.
I had a bug where the app would work fine on the simulator, but would crash when I ran it on a device because there was a bug in the device token code. I couldn't figure it out for the longest time!
There are many trivial examples. For example you can allocate far more memory on the simulator than on a real phone. You cannot receive push notification on the simulator if you don't have a retina Mac, the display dot pitch is different.
At a more fundamental level, the simulator is just that, it simulates the iPhone OS X using Mac OS X. This is evidenced by the fact that the filesystem on the simulator may not be case sensitive but on the phone it will be. More subtly, it does not emulate hardware so things like location will not work the same and 3D is going to be very different - especially if you are using Metal.
You should always test on real hardware.
Without considering the performance differences between the two, there used to be some things that the simulator didn't do correctly - i.e. it would mess up audio in some cases (see this question). However since the 2.2 SDK this issue has been resolved and the sound seems to be fine in the simulator. That's not to say that there is some other incompatibilities lurking down there! (Just none I've run into)
Regarding sounds, I was having the same problem. The issue was that the sound encodings that the Simulator supports is a different set of sounds than the device. I hope that helps.
I had many problems with libraries and frameworks when moving from the simulator to the device. Not least that they seem to have different architectures!
I have seen the positioning of objects, like toolbars be different on simulator than on the phone. Very annoying.
Yeah....
Apps compiled for 2.x will work fine on 3.0 device, but it will crash on 3.0Simulator
Note: 1. If you compile for 3.0, app will work fine on 3.0 simulator also...
2. a)Compile for 2.x and launch the app in simulator.
b)Now change the iPhone Simulator Hardware to "3.0".
c)Then launch the app we installed earlier in step a).
CRASH !!!!!!!!
movie file (m4v type) as my exprience is first time playing properly
but at second time it flickers screen of simulator...
whereas in iPhone device it works fime...
I had some sound effects that played fine in the simulator, but not on the device. I had to change the format to something that the device would handle.
If status bar of application is hidden,In case of simulator it still consumes touch event. But in the device it behaves perfectly.
Yes - it happened to me the other day. I'm new to the iphone, and so had deleted MainWindow.xib thinking it was unused. The app worked perfectly on the simulator - but crashed when installing on the phone.
Another issue we ran into was our three20 dependencies, which were set to ios 3.2 instead of 4.1. Worked perfectly in the simulator, but bombed on the device (since the files were compiled for the wrong arch).
iphone video library is not accessible
in simulator but code work fine on
actual device
Resource loading in the simulator is MUCH faster than in the device. For example, loading and displaying a sequence of full-screen UIImages (like a rudimentary video) can look very smooth in the simulator, and choppy on a device.
In fact, remember that there is a huge speed difference between different devices. The original iPhone and the iPhone 3G are slower than the iPod touch 2nd Gen, which is also much slower than the iPhone 3GS, and so on.
When trying to access the UIDevice.currentDevice(), it returns iOS Simulator instead of the actual device you're testing. This sucks, since you can't do certain things on the simulator.