Detect iOS Simulator vs. iOS Device - iphone

I am working on a project using Xamarin.iOS and I have a situation where a behavior in the simulator inexplicably is not the same on an actual device (setting the region of a mapview centers differently).
I want to be able to set a value for a variable at runtime based on whether the app is running on the simulator or a real device. How can I detect this?

You can execute different code at runtime like this:
if (ObjCRuntime.Runtime.Arch == Arch.DEVICE) {
} else {
}
But it's always good to investigate (ask around here, forums, bug reports) why the behaviour differs between the two (just to make sure it does not hide a bug that could bite you later).

Related

iphone - The purple location triangle does not go after calling stopUpdatingLocation

I am calling the following code when my app moves to the background -
[m_coreLocationMan stopUpdatingLocation];
However, the purple triangle still stays there. Do I need to do something else as well to make it go?
This is, quite simply, a very regularly occurring OS bug. We noticed this during testing of a large location-aware app. I've personally seen it happen quite often during normal everyday use with different apps.
No. Do you see that on the simulator? Device? What Xcode are you using? Try different simulators and on the device. In some combinations it may not work properly (betas, and some other things that can't be discussed here...)
As I asked there, did you try to also stopMonitoringSignificantLocationChanges ? It worked for me.

iphone Simulator crash?

I'm develop app for iPhone & iPod and during developing app i used simulator 3.2(iPad) it runs perfectly but when I want to my app on simulator 3.1.3 it generate one error I remove this error by comment this line //self.clearsSelectionOnViewWillAppear = NO;
and build project successfully but run app on simulator 3.1.3 when i clicking on button it goes on another screen on 3.2 simulator perfectly & crash on 3.1.3
what i do for come out from it.
The docs for UITableViewController clearly state that clearsSelectionOnViewWillAppear is available on iOS 3.2 and above. It crashes in 3.1.3 because this property does not exist in 3.1.3 (you can easily surmise this from reading the documentation for the property that you have already discovered is causing the issue, or from looking at the error message which will indicate that the object does not respond to a selector for setClearsSelectionOnViewWillAppear.
Before setting this, you can check for this property and then set it, otherwise your older code can just be supported as is, or you could do something more advanced and add the property in pre-3.2 environments.
To check for the code, you do something like this:
if( [UITableViewController instancesRespondToSelector:#selector(setClearsSelectionOnViewWillAppear:)] ) {
// This is 3.2+ so we can use this property
[self setClearsSelectionOnViewWillAppear:NO];
} else {
// This is something earlier than 3.2, so we ignore it
NSLog(#"will clear selection: pre-3.2");
}
Can you explain your question more clearly?
My dear friend,
You should read the Apple documentation more attentively,
It is clearly stated that
clearsSelectionOnViewWillAppear
is a method available from iPhone OS 3.2 and later,you are trying to use it in 3.1.3.
So the result is obvious.
clearsSelectionOnViewWillAppear
A Boolean value indicating if the controller clears the selection when the table appears.
#property(nonatomic) BOOL clearsSelectionOnViewWillAppear
Discussion
The default value of this property is YES. When YES, the table view controller clears the table’s current selection when it receives a viewWillAppear: message. Setting this property to NO preserves the selection.
Availability
Available in iPhone OS 3.2 and later.
Declared In
UITableViewController.h
Thanks

Make iPad app a Universal app

I have an iPad app that I would like to make Universal, however this seems alarmingly difficult. I've changed things around so that I support both builds, but when building, I get lots of errors about using UIPopOvers. Here're my questions:
Why does UI_USER_INTERFACE_IDIOM() not compile or register on 3.1.3?
Can I conditionally have variables in a class definition based on UI_USER_INTERFACE_IDIOM()?
If not, should I make two different view controllers?
Thanks!
Why does UI_USER_INTERFACE_IDIOM() not
compile or register on 3.1.3?
The UI_USER_INTERFACE_IDIOM macro is only available starting with 3.2. Same restrictions for the userInterfaceIdiom property of UIDevice. This means that you can only get universal application starting with SDK 3.2.
Can I conditionally have variables in
a class definition based on
UI_USER_INTERFACE_IDIOM()?
No. The UI_USER_INTERFACE_IDIOM macro is only a runtime shortcut to get the current UI idiom of the device.
If not, should I make two different
view controllers?
If you have very different UI between the two devices, it is wiser to use two different view controllers, and to create the right one at runtime (in the application controller for example) by using the UI_USER_INTERFACE_IDIOM macro.
I had pretty good luck with just selecting the target then going to Project->Upgrade current target for iPad.
My app is pretty simple, consisting mostly of table views and webviews, but it's worth making a backup and trying...
And yes, you have to submit it as a 3.2 app that can target 3.1.*
There are also a lot of other stuff that you have to do:
Make sure that it can be viewed at any orientation (got rejected the first time for this).
Make sure that you have all the new images created. you have to have 3 or 4 icons, instead of just one like an iPhone app needed. (iPad icon, iPhone icon, small icon for spotlight, etc).
And of course iPad sized screenshots for the store.
A really nice way that I use to test if it's an iPad or iPhone is to check if the device can use a split view controller, since for the forseeable future no device with a screen as small as an iPhone will be able to use the split view controller. I just created a function to do this for me:
+(BOOL)isIpad{ return NSClassFromString(#"UISplitViewController") != nil; }
Then anywhere in my app that I want to display something different depending on device, I just do a check for it:
int width = 150;
if([NabAppDelegate isIpad]){
width = 350;
} else {
width = 150;
}
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5,10,width,25)];
This is a lot better than checking against OS version like I've seen some suggest.

Difference in App load time when built for distribution?

This may sound like an odd question, but has anyone noticed that their iPhone apps launch quicker when built for distribution over being built for debugging?
Our app initially launches really slowly when compiling it for debugging / running it through xcode. (on device)
So I then dis-connected the phone from xcode and ran some extremely unscientific tests... (To try and quantify the slowness of the app)
Turned iPhone off then on. Booted my app. Counted to 6 mississippi's.
Closed app, re-launched it. Counted to 4 mississippi's.
Turned iPhone off then on. Booted 'contacts' app. Counted to 2 mississippi's.
Closed 'contacts' app, relaunched it. Counted to 2 mississippi's
The reason I compared to the contacts app is that it's pretty similar, UIWise to my own app. (Although its probably doing a lot more than my app is in the background).
My app is a navigation based app and the root view has the following elements:
UISearchBar
UISwitch
UIImageView
3x UILabels.
Not exactly a tasking amount of elements to initially load, so if there isn't a slight speed increase when building for distribution, I need to try and find the cause of whats taking the app so long to load!
One thing I thought could be the issue is that I'm using interface builder for the layout of my view(s). Could I be taking a loading hit as the initial view de-serializes?
Thanks for any input,
Jon
It's because the Distribution configuration is usually duplicated from the Release configuration in xcode, and has the "Strip debugger symbols" option turned on. Stripping symbols only used in debugging means there's less to load - which makes it faster.
I've noticed this before. I've always assumed that it has something to do with the iPhone interfacing with the Xcode debugger. I'm just guessing here, but I just tell myself it's telling the iPhone about any breakpoints and what to do when it hits them and stuff, among other "stuff". The iPhone is also probably talking to Xcode about keeping stuff in sync in case of a crash or something.

Xcode Performance Tool thinks the iPhone simulator has a camera

When I run this code in the Simulator in the debugger or standalone
[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]
it tells me the camera is not available (returns NO), as expected.
However, if I run the same code in the simulator in Performance Tool, it returns YES! My code (which works fine on device) then continues to display the camera view in the simulator. If I attempt to capture an image though, I get a console message
photos can only be captured on HW
Which means that if I want to profile my application on the simulator (wouldn't it be nice if it worked on the device!!) I need to go change the code so that it displays the correct view (i.e. not the camera one!).
This does not, from googling, appear to be a well-known issue. Has anyone else experienced it and/or got a workaround?
The obvious workaround is to add an
#if TARGET_IPHONE_SIMULATOR
But that's just icky. The whole point of doing the isSourceTypeAvailable in the first place is to avoid that sort of thing.