Skip to content

Instantly share code, notes, and snippets.

@buranmert
Created June 23, 2016 15:47
Show Gist options
  • Save buranmert/09f518503fa53c7653a6bce52f053d34 to your computer and use it in GitHub Desktop.
Save buranmert/09f518503fa53c7653a6bce52f053d34 to your computer and use it in GitHub Desktop.
Example View Controller for SDK
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "AFNetworking.h"
static NSString * const DummyModelUUID = @"a1303fcf-e6e2-4741-a028-82db4d566068";
@interface ViewController () <AGTViewControllerProtocol>
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
@property (weak, nonatomic) IBOutlet AGTView *ARView;
@property (nonatomic, strong) AGTAugmentPlayer *augmentPlayer;
@property (nonatomic, weak) NSOperation *currentOperation;
@property (nonatomic, strong) AFURLSessionManager *networkManager;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.augmentPlayer = [AGTAugmentPlayer new];
self.networkManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
[self.ARView setAugmentPlayer:self.augmentPlayer];
[self initiateARSession];
}
- (void)foo {
[self.activityIndicator startAnimating];
__weak typeof(self) weakSelf = self;
void (^progressBlock)(NSProgress *progress) = ^void(NSProgress *progress) {
NSLog(@"progress: %%%f", progress.fractionCompleted);
};
void (^completionBlock)(NSString *modelIdentifier, NSError *error) = ^void(NSString *modelIdentifier, NSError *error) {
[weakSelf.activityIndicator stopAnimating];
if (error == nil && modelIdentifier != nil) {
NSLog([NSString stringWithFormat:@"ViewController: model with id %@ added", modelIdentifier]);
[weakSelf startAR];
}
else {
NSLog(@"ViewController: an error occurred");
}
};
self.currentOperation = [self.augmentPlayer addModelWithIdentifier:DummyModelUUID
networkManager:(id<AGTNetworkManagerProtocol>)self.networkManager
progress:progressBlock
completion:completionBlock];
}
- (void)initiateARSession {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusAuthorized) {
[self foo];
}
else if (authStatus == AVAuthorizationStatusNotDetermined) {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo
completionHandler:^(BOOL granted) { if (granted) { dispatch_async(dispatch_get_main_queue(), ^{[self foo];});} }];
}
}
- (void)startAR {
[self.augmentPlayer initializeAREnvironment];
[self.augmentPlayer resume];
[self addDefaultARGestureRecognizersOnView:self.ARView];
}
- (IBAction)cancelButtonTapped:(UIButton *)sender {
[self.currentOperation cancel];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment