Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-17-2009, 01:59 AM   #1 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default UIImagePickerController Woes

Hello All,

I am trying to just set up a UIImagePickerController to take a picture using the Camera and I am having a tough time. Been at all night trying to implement code from tutorials and just not getting it to happen...it's one of those nights. Can anyone please just post the source code for allocating a UIImagePickerController geared for taking pictures programatically (I don't want to use InterfaceBuilder at all). I know somethings, like the delegate that is specified has to implement the proper protocol and the like.

For reference, as I read it might matter, I want to have the UIImagePicker live in a UIView called MainView, which is an instance variable of my RootViewController (which is a UIViewController) which in turn is an instance variable of my Application Delegate. (So it is AppDelegate--->RootViewController--->MainView---->The picker lives here.

I know this is probably a silly thing that everyone can do; but it's just kicking the crap out of me right now and I gotta go to sleep...work tommorow morning.

Thanks.
scotopia is offline   Reply With Quote
Old 02-17-2009, 09:45 AM   #2 (permalink)
Registered Member
 
tkilmer's Avatar
 
Join Date: May 2008
Posts: 583
Default

If it were directly in the view controller, it is simple to display. All you have to do is presentModalViewController: animated:

Here is what I do when I present it in a UIView instead of a UIViewController:
Code:
 UIImagePickerController *pc = [[UIImagePickerController alloc] init];
pc.delegate = self;
pc.sourceType = UIImagePickerControllerSourceTypeCamera; //or album
pc.xxxx //a lot of other options you could specify
[self addView:pc.view];
Make sure you end up releasing it in the delegate call backs.
tkilmer is offline   Reply With Quote
Old 02-17-2009, 10:17 AM   #3 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default

Oh, so my problem was probably that I was trying to implement it in a UIView and not a UIViewController. I already have my application hierarchy the way I want and don't want to change it....I suppose I can just make Mainview a UIViewController instead of a UIView?

Thanks.
scotopia is offline   Reply With Quote
Old 02-17-2009, 11:38 AM   #4 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default

Can anyone confirm what I said? (at work right now so can't test it). Thanks!
scotopia is offline   Reply With Quote
Old 02-17-2009, 12:50 PM   #5 (permalink)
Registered Member
 
tkilmer's Avatar
 
Join Date: May 2008
Posts: 583
Default

You could probably make it a view controller, but test what I posted when you get back from work. It works for one of my apps.
tkilmer is offline   Reply With Quote
Old 02-17-2009, 01:14 PM   #6 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default

Yes that's more or less the code I had in my Mainview, but all it did was show a light blue colored toolbar or some such at the top of the screen. Perhaps it just simply has to be in a UIViewController and not a UIView... i noticed that I got a warning that the UINavigationControllerDelegate Protocol needed to be implemented, in addition to the UIImagePickerControllerDelegate Protocol, which I thought strange (probably because it wasn't a UIViewController which I guess has the nav protocol built in).
scotopia is offline   Reply With Quote
Old 02-17-2009, 01:37 PM   #7 (permalink)
Registered Member
 
tkilmer's Avatar
 
Join Date: May 2008
Posts: 583
Default

You still have to implement that delegate. The UIImagePickerController inherits from the navigation controller. That is why you are required to implement that delegate as well. All you have to do is add it to your header file, then the warning disappears. You actually dont have to put any code in to work with the nav controller delegate.
tkilmer is offline   Reply With Quote
Old 02-17-2009, 07:38 PM   #8 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default

WTF I just got home and I tried to implement it this way; and again all I am seeing is a light blue bar at the top of the screen.
scotopia is offline   Reply With Quote
Old 02-17-2009, 07:41 PM   #9 (permalink)
Registered Member
 
tkilmer's Avatar
 
Join Date: May 2008
Posts: 583
Default

post your code...
tkilmer is offline   Reply With Quote
Old 02-17-2009, 07:51 PM   #10 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default

It is exactly what you posted above. I just have UIView called Mainview (that is getting displayed just fine) where the only thing I want it do is get this camera thing going.

Here is the (unintersting) code for the m file:

Code:
#import "MainView.h"
#import "RootViewController.h"
#import "MyAppDelegate.h"


@implementation MainView

@synthesize myAppDelegate, rootViewController;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
		//[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
		[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO ];
		
		//[self setBackgroundColor:[UIColor whiteColor]];
		//set up delegate
		MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
		self.myAppDelegate = appDelegate;
		[appDelegate release];
		
		self.rootViewController = self.myAppDelegate.rootViewController;	
		
		UIImagePickerController *pc = [[UIImagePickerController alloc] init];
		pc.delegate = self;
		pc.sourceType = UIImagePickerControllerSourceTypeCamera; //or album
		[self addSubview:pc.view];
    }
    return self;
}


- (void)drawRect:(CGRect)rect {
    // Drawing code
}


- (void)dealloc {
	[myAppDelegate release];
	[rootViewController release];
    [super dealloc];
}


@end

This class implements the proper delegates and there are no errors or warning. I think I have all frameworks necessary. I didn't write the code for the delegate functions because I was just testing...maybe thats my problem. What am I missing? I wish the damn apple docs would always come equipped with a full implementation example code.....

Could you do me a favor and just post the .m file code for a UIView that all it does is this lol! Thanks...

Last edited by scotopia; 02-17-2009 at 07:54 PM.
scotopia is offline   Reply With Quote
Old 02-17-2009, 07:59 PM   #11 (permalink)
Crafty Veteran
 
Magic Hands's Avatar
 
Join Date: Nov 2008
Location: Memphis, TN
Age: 23
Posts: 436
Send a message via Skype™ to Magic Hands
Default

This is what I use, hopefully it helps:
Code:
//--------------------------Handles Picking--------------------------
-(void)openPicker 
{
	if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) 
	{
		UIImagePickerController *picker;
		picker = [[UIImagePickerController alloc]init];
		picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
		picker.allowsImageEditing = YES;
		picker.delegate = self;
		[self presentModalViewController:picker animated:YES];
	}
}

-(void)imagePickerController:(UIImagePickerController *) picker
	   didFinishPickingImage:(UIImage *)imag 
				 editingInfo:(NSDictionary *)editingInfo  
{
	
	someImage = imag;
        [someImage retain];
	//Call some method here that you want to call after they take the picture
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerController:(UIImagePickerController *) picker 
{
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}

-(UIImage*)getTheImage
{
	return  image;
}
-(void)setTheImage:(UIImage*)img
{
	image = [img retain];
}
Good luck!
Magic Hands is offline   Reply With Quote
Old 02-17-2009, 08:23 PM   #12 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default

Thanks for that; so, since it is using present modal view I have to make MainView a UIViewController correct? Tkilmer, do you recommend this approach as well, or do you think another approach is more suited to my scenario? Thanks all!
scotopia is offline   Reply With Quote
Old 02-17-2009, 08:33 PM   #13 (permalink)
Registered Member
 
tkilmer's Avatar
 
Join Date: May 2008
Posts: 583
Default

I would personally go with the view controller. If it does not work for you, just revert back and try to find another solution.
tkilmer is offline   Reply With Quote
Old 02-17-2009, 11:56 PM   #14 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default

Arg...Now I am just getting a blank screen. I have verified through breakpoints that the call to create the picker and display it gets executed (and also that the call to dismiss it is NOT called)...I don't know what I am doing wrong? I literally just changed the UIView to a UIViewController and made the minor tweaks necessary (self.view here and there instead of self) and copied the code above.... When I transition to this view the app seems to think for a second; but then only a black screen is shown (or if i put a toolbar in MainView.view for example that will show up; so the view is displaying fine; just no camera). There are no errors or warnings; and I am trying it on the Device itself, not just the Sim.

I'm at my wits end; please assist me. Thank you!
scotopia is offline   Reply With Quote
Old 02-18-2009, 01:15 AM   #15 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 812
Default

UIImagePickerController is designed to run as a model view controller. It shouldn't be pushed. I know it is OK to push in SDK 2.0 but that won't work in 2.2.

Do the PresentModalController from your main controller and it will work fine.
johnqh is offline   Reply With Quote
Old 02-18-2009, 01:19 AM   #16 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default

I actually tried that; I got rid of the mainView alltogether and tried to implement it in my RootViewController UIViewController object; no dice. I think I'm just at that point where I'm just cursed and nothing I can do can work.

If anyone can just simply send me a working xcode project that just has a RootViewController pulling up the camera in its viewDidLoad method I'd be much appreciative. Basically just the simplest sample app that fires up the camera. At this point I just need to look at the simplest thing that actually works and build up from there.

Thanks.
scotopia is offline   Reply With Quote
Old 02-18-2009, 01:40 AM   #17 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 812
Default

Quote:
Originally Posted by scotopia View Post
I actually tried that; I got rid of the mainView alltogether and tried to implement it in my RootViewController UIViewController object; no dice. I think I'm just at that point where I'm just cursed and nothing I can do can work.
Did you use presentModalController, or did you add the view to your view?
johnqh is offline   Reply With Quote
Old 02-18-2009, 01:42 AM   #18 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 812
Default

I would suggest you to create a blank project, and make it work in the blank project first. Maybe something else in your project is conflicting with it.
johnqh is offline   Reply With Quote
Old 02-18-2009, 01:44 AM   #19 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default

Quote:
Originally Posted by johnqh View Post
I would suggest you to create a blank project, and make it work in the blank project first. Maybe something else in your project is conflicting with it.

I used present; in a blank new project. Like I said; I'm at that point where I am just cursed; no errors, no warnings and everything looks right. Just...nothing.

I'm not trying to be crafty and get other people to do the work for me; I've been at this for two days and its making me go batty; it wold be simple if the docs were just like: here's this class and here is a sample of how its implemented. Even in research assistant it says Example Code: 0.

Also I don't think its terrible just asking for someone to send me this sample project in it with nothing but this; it's not proprietary code or anything and its something that should be in a apple sample app anyway....arg, I got to go to sleep; another night completely wasted with no information gained...that's just the worst thing ever.

Last edited by scotopia; 02-18-2009 at 01:54 AM.
scotopia is offline   Reply With Quote
Old 02-18-2009, 02:44 AM   #20 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 495
Default

Not sure if this is what you're looking for, but may be worth a shot : Creating a Full-Screen Camera Preview - Inside iPhone Blog
__________________
My Apps on AppStore : gScale (guitar scales reference), eMaze, eMaze Lite, eTimesheet
exorcyze is offline   Reply With Quote
Old 02-18-2009, 10:21 AM   #21 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default

Thanks for the reply Ex.

I don't even need anything nonstandard like that. I'm just looking for the normal implementation of this working; I don't know why its not working for me. I'm literally just making a new project, making a UIViewController object that has the above camera implementation code. No errors; I can verify that the view of the UIViewController is being displayed; and I can verify via breakpoints that the code to present the modal view is being executed....nothing happens and I don't know why. I got the right framworks; the ViewController implements the right delegates etc...ugh.

That's why I am just basically begging anyone to just send me an xcode project with what I am stating above; it should literally take about 2 minutes to create from scratch.
scotopia is offline   Reply With Quote
Old 02-18-2009, 11:11 AM   #22 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 812
Default

So it doesn't work in a blank project?

Well, maybe something is not initialized correctly. That's why IB is easier. Why not try that?
johnqh is offline   Reply With Quote
Old 02-18-2009, 11:14 AM   #23 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default

Quote:
Originally Posted by johnqh View Post
So it doesn't work in a blank project?

Well, maybe something is not initialized correctly. That's why IB is easier. Why not try that?
I suppose I could do that; but I generally like to avoid IB; plus, its a matter of principle now; I NEED to know
scotopia is offline   Reply With Quote
Old 02-18-2009, 11:53 AM   #24 (permalink)
Registered Member
 
tkilmer's Avatar
 
Join Date: May 2008
Posts: 583
Default

making a quick one and sending it to you through email.
tkilmer is offline   Reply With Quote
Old 02-18-2009, 11:55 AM   #25 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,028
Default

Quote:
Originally Posted by tkilmer View Post
making a quick one and sending it to you through email.

Thank you god.
scotopia is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 271
16 members and 255 guests
@sandris, ADY, dacapo, Dani77, djohnson, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, timle8n1, tomtom100
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:03 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0