samedi 29 novembre 2014

How can I start a ViewController from within a Method?

I want to use the TGCameraViewController from within a iOS Cordova Plugin method.


Here is the implementation of the method:



#import "BCamera.h"
#import "TGCameraViewController.h"

@implementation BCamera

// Cordova command method
-(void) openCamera:(CDVInvokedUrlCommand *)command {

// take a photo

}


From the documentation of the TGCameraViewController I have to use the following to take a photo:



#import "TGCameraViewController.h"

@interface TGViewController : UIViewController <TGCameraDelegate>

@property (strong, nonatomic) IBOutlet UIImageView *photoView;

- (IBAction)takePhotoTapped;

@end



@implementation TGViewController

- (IBAction)takePhotoTapped
{
TGCameraNavigationController *navigationController =
[TGCameraNavigationController newWithCameraDelegate:self];

[self presentViewController:navigationController animated:YES completion:nil];
}

#pragma mark - TGCameraDelegate optional

- (void)cameraWillTakePhoto
{
NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)cameraDidSavePhotoAtPath:(NSURL *)assetURL
{
// When this method is implemented, an image will be saved on the user's device
NSLog(@"%s album path: %@", __PRETTY_FUNCTION__, assetURL);
}

- (void)cameraDidSavePhotoWithError:(NSError *)error
{
NSLog(@"%s error: %@", __PRETTY_FUNCTION__, error);
}

#pragma mark - TGCameraDelegate required

- (void)cameraDidTakePhoto:(UIImage *)image
{
_photoView.image = image;
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)cameraDidCancel
{
[self dismissViewControllerAnimated:YES completion:nil];
}

@end


How do I use this example to open the camera view from within my openCamera method?




Aucun commentaire:

Enregistrer un commentaire