Xcode Performance Tool thinks the iPhone simulator has a camera - iphone

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.

Related

Detect iOS Simulator vs. iOS Device

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).

Crash upon iPhone Simulator 5.0 startup

I'm making an iPhone RPG application, I was working on programming a CGPoint array to some sprites I wanted to add, but I didn't make any progress and thus deleted the code.
After this, an exception was thrown each time I ran the app' on the iPhone Simulator, it said it was to do with OpenAL, so I took all of the sound code out.
The project then ran fine on the iPhone Simulator, without sound though of course.
Now, upon taking all of my newly added code out, the iPhone Simulator crashes (freezes) when it's still on the Cocos2d load up screen and points to the following line of code in Xcode:
int retVal = UIApplicationMain(argc, argv, nil, #"AppDelegate");
I've been looking over my code with a fine-tooth comb for an hour now, checking in case I left any code in or changed anything, and I haven't.
Has anyone had any experience with this problem? Or can anyone give me an idea what might have happened?
Some light to shine on the OpenAL problem would be nice too (second time it's happened to me).
The best thing to do in situations such as these is put break points all over the place and look for the point at which the applications crashes from.
If you haven't yet check out the stack for any clues. Unfortunately if there is nothing on the stack or printed from the debugger this is really all you can do.
So I checked some other questions AGAIN, and found someone saying to restart the computer... This worked. It's annoying, so so annoying. But that's what worked.
Also, for any weird errors, just make sure you Product > Clean after adding/changing any resources you use.

Universal app working on iPad 1 but not on iPad 2

First of all I want to say that I'm I aware that my question is probably way too vague to answer and may be closed/down-voted. I just hope for some inspiring brain-storming on possible solutions.
Here's the story:
My app was crashing on iPad 2, but not on iPad 1. I've fixed the crash related to unarchiving nib and now I have a very strange problem - my universal app still runs without any problems on 1st gen iPad with iOS 4.2.1 and 4.3.3, but not on (some/all?) iPads 2 with 4.3.3. Unfortunately I don't have an access to iPad 2 with iOS < 4.3.3 to test further and narrow down the problem.
My app has it's main screen displayed by using presentModalViewController. My modal VC is MGSplitViewController (it mimics native UISplitViewController and enhances its functionality). When my VC is presented, only "root view" is displayed and remaining part of screen for "detail view" is just black and empty however the controller is loaded and active (debug logs are printed etc.).
So on iPad 2 I have access to, it fails to display detail view properly, however I've heard from one user that it's fine on his iPad 2 (both iOS 4.3.3). App also works ok on iPhone/iPod regardless iOS version, so I assume it's related only to iPad code of my universal app.
I believe it may be more general issue with displaying views. I've tried to read view property of my detail view, which should force view to be displayed, but it didn't help. It may also be related to IB stuff (the initial nib unarchiving crash only on iPad 2??), but I think everything is wired ok in IB...
Anyone has a slightest idea how to investigate this problem?
EDIT: BTW: My iPad 2 is giving me hard time as it drops Wi-Fi connection very often. Other people are also reporting this kind of "feature". Can it be that it's just something wrong with my iPad 2?
EDIT2: the app is also not correctly displayed on iOS 3.2, 4.2 and 4.3.3 Simulator (via XCode 4), but gets displayed correctly on iOS 3.2, 4.2 Simulator via Xcode 3. Strange, isn't it?
Anyone has a slightest idea how to investigate this problem?
If you'll allow a somewhat vague answer to a somewhat vague question, then yes, I do have an idea.
To approach problems like this in general, bisection of the problem field is a great way to go forward:
You identify the general problem area. Could it be presentModalViewController in your case?
Then about halfway through the code in question, you set a breakpoint/write a message to a log file/play a sound/send a mail/tweet/whatever it takes to verify that your code has come that far without a crash.
Run it and see if your message has been produced.
If it has been produced, the problem is not in the first half, so it must be in the second half (a log message at the end of the identified problem area is useful, too, just to make sure that the crash actually happens before that).
On the other hand, if there is no trace of your log message, then the crash must occur in the first half, and you can rule out the second half of your code for this particular problem.
Now you repeat the algorithm by setting your breakpoint/log message about halfway into the culprit half you just identified.
Repeat until you find the problem. It won't take many iterations.
Of course, the crash may be due to some variable stored at a previous step or in another method, but now you know where to look.
Initially the app was crashing due to unarchiving the nib. I don't recall the exact crash output, but it was quite strange for me that same nib was properly unarchived on iPad 1 with same OS version, so I suspected that the problem lies in xib file... I've recreated the xib from scratch routing everything carefully and - bam! - it started working on both iPad 1 and iPad 2! How come some nibs aren't unarchived in a same way on same OS running different HW???

Debugger does not stop at breakpoints when running on iPhone device

I want to test my app on device and see all the NSLOGs on console while runnig the ap on device.I also want to stop the app at breakpoints but app does not stop on breakpoints and not print NSLOGs .I have unchecked load symbols lazily .I am using a debug build .Please tell me how to achieve this
Thanks in advance
NOTE:After starting the app x code shows the app being debugged is not being run (I think the problem is after xcode transfers the app to device then it disconnects with device)
Do you have breakpoints enabled in xCode?
Should be looking like this;
Try to set breakpoint in the didFinishLaunchingWithOptions then the viewwillappear of the view you want to test the breakpoints on. basically any places before your code (which you want to test) which surely get called.
I had same problem before not exactly sure why does it happen though.
it's like preparing Xcode to look for breakpoints :)
Sounds like you're working with a jailbroken device .. Is that the case ?
If you are , the "official" answer should be "disable mobileSubstrate addons".
I've managed to run the app in debug mode , after :
Doing what you mentioned (got that error message).
Double tap home-button , hold the app icon, close the app..
Run it again from XCode.
Repeat again if necessary.

My Iphone App crashes (Bad access) when turned on it's side (landscape mode)

For some reason, every time I run my Iphone App, the App works fine as long as it is upright. The second the simulator turns to the left or right (like if I manually turn it, or if it's trying to play a video), the code crashes, with either a "Bad Access" or an exception.
The crazy thing is that this stuff was JUST working, and I didn't change ANYTHING that looks like it would affect landscape mode only. Could something complicated in the background have changed to make this stop working? Is this just a symptom of some sort of memory error?
-Jenny
Sure, you could be releasing something which should shouldn't release yet, or similar.
I'd put some NSLog statements in key places, start with shouldAutorotateToInterfaceOrientation and in any custom drawing functions you may have.