UIImagepickerController [takepicture] modal view disappears no delegate callback - iphone

Update:
This has been answered. It was my own stupidity, possibly not worth reading any more of this question. lol.
Question:
Right so i have this UIViewController(master) subclass, it has a UIImagepickerController(camera), it also has a UIView(overlayView). Master setups the camera to be configured as a camera only with a custom cameraOverlay, hiding the custom controls e.t.c.
All appears to work fine apart from when i try to programatically take a picture. What happens is the overlayView calls the master and this triggers the take picture, then i hear the shutter sound and the iris closes, the camera appears to dismiss itself (i am defiantly not doing this in my code) and then my viewDidAppear gets called in my master again.
Anybody have any idea whats going on ?
-(void)viewDidLoad
{
NSLog(#"loading the view");
//if the camera is on the device
if ( [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
//make one
camera = [[UIImagePickerController alloc] init];
//setup some settings that we need
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
camera.showsCameraControls = NO;
camera.navigationBarHidden = NO;
camera.toolbarHidden = YES;
camera.cameraViewTransform = CGAffineTransformScale(camera.cameraViewTransform, 1.03, 1.03);
//show it
overlayView = [[OverlayView alloc] initWithFrame:CGRectMake(0,0,320,480) withDelegate:self andController:self];
camera.cameraOverlayView = overlayView;
camerashowing=NO;
}
else
{
alert = [[UIAlertView alloc] initWithTitle:#"No Camera Detected" message:#"The camera is broken or your device has no camera. Please close the application" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
}
-(void)viewDidAppear:(BOOL)animated
{
if (!cameraShowing)
{
NSLog(#"going to show camera");
[self presentModalViewController:camera animated:NO];
camerashowing = YES;
}
}
-(void)releaseShutter
{
[overlayView toolbarShowWarning];
NSLog(#"going to show camera: %#", self);
[camera takePicture];
}
After some help advice from people in the answers i can say that the camera is not being released.
I have also managed to stop the exec_bad_access by stopping it from calling [presentmodal....] for a second time by checking a bool value in the viewDidAppear Method.
I still have the issue where the modal view disapears, any help, again lol ??

I think you're missing a camera.delegate = self;

For any EXC_BAD_ACCESS errors, you are usually trying to send a message to a released object. The BEST way to track these down is use NSZombieEnabled.
This works by never actually releasing an object, but by wrapping it up as a "zombie" and setting a flag inside it that says it normally would have been released. This way, if you try to access it again, it still know what it was before you made the error, and with this little bit of information, you can usually backtrack to see what the issue was.
It especially helps in background threads when the Debugger sometimes craps out on any useful information.
VERY IMPORTANT TO NOTE however, is that you need to 100% make sure this is only in your debug code and not your distribution code. Because nothing is ever released, your app will leak and leak and leak. To remind me to do this, I put this log in my appdelegate:
if(getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled"))
NSLog(#"NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");
If you need help finding the exact line, Do a Build-and-Debug (CMD-Y) instead of a Build-and-Run (CMD-R). When the app crashes, the debugger will show you exactly which line and in combination with NSZombieEnabled, you should be able to find out exactly why.

Check the value of the camera member variable before you try and display it:
NSLog(#"going to show camera: %#", camera);
I suspect it might be being released somewhere, but as coneybeare NSZombieEnabled will let you track it down.

Related

Is MPNowPlayingInfoCenter compatible with AVAudioPlayer?

I start -play with AVAudioPlayer, and then set the nowPlaying dictionary like this:
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
        
MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imagedNamed:#"AlbumArt"]];
[songInfo setObject:#"Audio Title" forKey:MPMediaItemPropertyTitle];
[songInfo setObject:#"Audio Author" forKey:MPMediaItemPropertyArtist];
[songInfo setObject:#"Audio Album" forKey:MPMediaItemPropertyAlbumTitle];
[songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
The lock screen always shows a pause button. I receive the remote control events correctly and I can toggle play/pause through the remote control events, but the lock screen keeps showing "pause" even when it is playing.
Now I seen this work with MPMoviePlayerController. Can someone explain how does the MPNowPlayingInfoCenter determine if it should show a play or a pause button?
Have you set the correct AVAudioSessionCategory on the AudioSession? it needs to be AVAudioSessionCategoryPlayback I believe to get it to work.
I'm not using MPNowPlaying at the moment, but apparently I have to, in order to get the audio info displayed on the lock screen.
However, in addition to what #user3061915 said, to manage the play/pause button, I've used UIEventTypeRemoteControl and it works perfect for controlling the play/pause button:
- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
//if it is a remote control event handle it correctly
if (event.type == UIEventTypeRemoteControl)
{
if (event.subtype == UIEventSubtypeRemoteControlPlay)
{
[self playAudio];
}
else if (event.subtype == UIEventSubtypeRemoteControlPause)
{
[self pauseAudio];
}
else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause)
{
[self togglePlayPause]; //This method will handle the toggling.
}
}
I just fixed a problem like this in my own app. I originally used [[AVAudioSession sharedInstance] setCategory:withOptions:error:] and supplied AVAudioSessionCategoryOptionMixWithOthers and AVAudioSessionCategoryOptionDuckOthers. This turned out to be my problem. If you set mix with others, you get no remote control events. They still go to the iPod app. If you set duck others, you get remote control events, but it appears as though it causes the problem you describe: the play/pause button shows the wrong thing. I'm not sure why. I got the play/pause button to behave by setting options to 0, or actually just calling setCategory:error:.

Camera button on UIImagePickerController is randomly disbled

I have a UIImagePickerController (source type camera) that I use to take pictures. I have it put properly in my .h (added the #property) and .m (#synthesize). Here's what I use to show it:
if (thePicker == nil) {
thePicker = [[UIImagePickerController alloc] init];
thePicker.delegate = self;
thePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
thePicker.allowsEditing = NO;
}
[self presentModalViewController:thePicker animated:YES];
I'm having an odd problem. Every now and again, after closing/opening it a few times, the camera button OR the used button won't work (but the retake and cancel buttons work). I'm not getting any memory warnings and I have a dealloc and didReceiveMemoryWarnings void statement, but they don't get called.
ANyone else having this problem?
I have seen some apps cover it up with their overlay, but you can't remove it. AVCaptureSession really does sound more appropriate for your purposes. I see one example here:
http://www.musicalgeometry.com/?p=1273
Try this it may help u i guess Thanks!!

iPhone GameCenter won't showAchievments

So my problem is that after integrating gamecenter nicely into my iphone app, it won't show the achievements list!
The integration was a success I think because when I use the submitAchievement method, I do unlock achievements on the list. But I must look at the list from the GameCenter App on the iPhone, not within my own app as it doesn't work.
ikuragames first help me get the code right (thx you !!) but it still doesn't work ! :(
-(void)showAchievments
{
//NSLog(#"showAchievments");
GKAchievementViewController *achievements = [GKAchievementViewController alloc] init];
if (achievements != nil)
{
achievements.achievementDelegate = self;
[(EAGLView *)self.view achievmentsWillAppear];
[self presentModalViewController:achievements animated:YES];
}
}
- (void)achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
//NSLog(#"achievementViewControllerDidFinish");
[glView achievmentsWillDisappear];
[self dismissModalViewControllerAnimated:YES];
}
On debug mode, I can clearly see that each line or code are "processed" and not error whatsoever is displayed. BUT, nothing appears on my screen :(
Can you please help me ? (here is some doc.)
I found the answer.
Turned out that the view controller I was sending showAchievments to was not the view controller I wanted.
I was doing something like:
[[myViewController sharedInstance] showAchievments];
But the sharedInstance method returned a brand-new, vanilla-initialised myViewController, and not the one I was already using.
Now it works perfectly, I hope this will help someone in the future.

UIImagePickerController Camera Source Problem

Ok here is the code that I wrote to display the UIImagePickerController in the camera source. I just declared the myPhotopicker in the header for the property and retain it. Synthesized it in the main code file. Then calling the picker I wrote the code below:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
if (myPhotopicker==nil) {
myPhotopicker = [[UIImagePickerController alloc] init];
myPhotopicker.delegate = self;
}// create once!
myPhotopicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:myPhotopicker animated:NO];
}
Upon calling it, there are a few things that is weird happening to the app.
Sometimes, when there are many apps running in the background (iPhone4), the app would fail to load the camera and crash the app. Though it will load CameraRoll/PhotoAlbums without problem.
If the camera view is able to load (when there are less apps running in the background), tapping the Cancel button on the camera view results in the app rebooting itself (where the Default.png image is shown quickly, and back to the main page - like when we started the app).
I have been trying to figure out this problem, but not sure what to do... pls help.. Thanks.
here is the complete code of image pickercontrol try too find solu. here.
http://www.icodeblog.com/2009/07/28/getting-images-from-the-iphone-photo-library-or-camera-using-uiimagepickercontroller/
Regards,
Shyam Parmar
Rather than your 'create once' logic try creating and releasing each time.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
myPhotopicker = [[UIImagePickerController alloc] init];
myPhotopicker.delegate = self;
myPhotopicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:myPhotopicker animated:NO];
[myPhotopicker release];
}
You should also implement the delegate to remove the modal view controller from view when it is dismissed (if you haven't already).
You should also check that the current class conforms to the UINavigationConrollerDelegate protocol.

UIImagePickerController Camera Source causing the app to crash

I am getting "Received memory warning. Level = 1" when I use UIImagePickerControllerSourceTypeCamera.
If I access the camera immediately after entering the application, I get "Received memory warning. Level=1" but when I select the camera option after accessing all the other functionality in the application, the app crashes while the debugger console displays
Received memory warning. Level=1
Program received signal: “EXC_BAD_ACCESS”.
Why does this happen? I don't get any memory leaks notification when I build and analyze.
if(actionSheet.tag == 1){
addButton.enabled = YES;
UIImagePickerController * picker = [[[UIImagePickerController alloc] init] autorelease];
picker.delegate = self;
if (buttonIndex == 0)
{
NSLog(#"selecting camera");
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
else if (buttonIndex == 1){
NSLog(#"choosing album");
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
else
{
//NSLog(#"cancel");
}
}
EXC_BAD_ACCESS normally is the opposite of a leak: An overreleased object. An object which retain count has dropped to 0 but you still hold a pointer to it somewhere. Once you access this pointer you may receive EXC_BAD_ACCESS, or other strange behavior.
There's other possibilities, too. It just means your trying to access memory, that you do not own.
In your case this does not necessarily have to do with the UIImagePickerController. The presenting of the picker just causes a memory warning to be posted, and in reaction to this warning your app releases memory in various different places. My guess is, that at least one of these objects has already been released before, and is a dangling pointer now.
To debug this you should try NSZombieEnabled. See this question for further help on finding this kind of bug: EXC_BAD_ACCESS signal received
P.S.: You should have found it when searching for for EXC_BAD_ACCESS
It is because the UIImagePicker fired your ViewDidUnload.
So that all the instance become Zombie.
Therefore, the direction to handle this problem is
"Why UIImagePicker" triggered the ViewDidUnload.
I have the same problem, and cannot found the solution yet.