views:

242

answers:

3

I have never made an app using XCode and Cocoa but I think following these instruction:

http://developer.apple.com/Mac/library/documentation/GraphicsImaging/Reference/IKImagePicker%5FClass/IKImagePicker%5FReference.html

I could easily make an app that pops up a window that allows you to push a button to bring up the IKPictureTaker, but this is not quite what I want. I want my app to just automatically bring up the PictureTaker. I assume to do this I would have to abandon the interface builder altogether and do the whole thing programatically but I can't figure out what call will tell the Cocoa app to use this class or method at start up. Where would this be done programatically? I am trying to do all this in a Cocoa app that will be run in OSX.

alt text

+1  A: 

You'll want to use the beginPictureTakerWithDelegate:didEndSelector:contextInfo: method, which will give you a stand-alone pictureTaker window.

IKPictureTaker *sharedPictureTaker = [IKPictureTaker pictureTaker];

[sharedPictureTaker setValue:[NSNumber numberWithBool:YES] forKey:IKPictureTakerShowEffectsKey];

[sharedPictureTaker beginPictureTakerWithDelegate:self didEndSelector:@selector(pictureTakerDidEnd:returnCode:contextInfo:) contextInfo:nil];

If you put that somewhere, like in your Application Delegate's applicationDidFinishLaunching: method, you'll get the picture taker window @ startup.

Jess Bowers
Thank you very much for this response. I am just still a little bit confused. Where do I access the Application Delegate? If I have a blank Cocoa Project in XCode I don't seem to have access to the NSAplication, do I need to create the delegate? Or is hidden somewhere?
Mike2012
From scratch, you can do it by New Project -> Cocoa Application. Then look @ the ApplicationDelegate class automatically created. Otherwise, you just link a custom class in IB by command dragging to it from the Application icon.
Jess Bowers
A: 

If you want a more custom solution you can look into the QuicktimeKit. It's not as easy as the three liner posted above but it's relatively pain-free. You'll have much more flexibility in the look of your picture taker window, be able to select from any number of inputs, be able to add your own filters, etc. Could be worth a look.

I'm not totally familiar with the IKPictureTaker. If it does something I'm not crediting it then let me know.

Randaltor
A: 

The way to automatically instantiate a class in Xcode /Cocoa is, strangely enough, through Interface Builder (IB). Open your MainMenu.xib in IB and make sure you can see the Document window (menu Window >> Document). Now, in the Library expand Cocoa >> Objects & Controllers >> Controllers. You'll see a number of controller, among them a blue cube. Drag this blue cube to your MainMenu.xib document window. You'll see that File's Owner and Font Manager sport the same blue cubes as their logo. Now, select your blue cube and in the Inspector choose the Identitiy panel (letter i on blue circle). Set the Class to the class you created before in Xcode, and save MainMenu.xib. When you run your program, your class will automatically be instantiated. Your starting point from where you can start calling other methods or instantiating other objects is

- (void)awakeFromNib
{
    NSLog(@"%@ I'm alive!", [self class]);
}
Elise van Looij