Skip to content

Instantly share code, notes, and snippets.

@Genki-S
Created October 25, 2015 18:40
Show Gist options
  • Save Genki-S/fca3512aeb5a4564168a to your computer and use it in GitHub Desktop.
Save Genki-S/fca3512aeb5a4564168a to your computer and use it in GitHub Desktop.
//
// ViewController.m
// ScienceHackDay
//
// Created by Genki Sugimoto on 24/10/2015.
// Copyright © 2015 Genki Sugimoto. All rights reserved.
//
#import "ViewController.h"
static const NSString *IP_ADDR = @"172.31.32.25";
static const NSString *PORT = @"4567";
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidAppear:(BOOL)animated {
NSArray *types = @[AVMetadataObjectTypeQRCode];
_reader = [QRCodeReaderViewController readerWithMetadataObjectTypes:types];
// Set the presentation style
_reader.modalPresentationStyle = UIModalPresentationFormSheet;
// Using delegate methods
_reader.delegate = self;
[self presentViewController:_reader animated:YES completion:NULL];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - QRCodeReader Delegate Methods
- (void)reader:(QRCodeReaderViewController *)reader didScanResult:(NSString *)result
{
[self dismissViewControllerAnimated:YES completion:^{
NSString *urlString = [NSString stringWithFormat:@"http://%@:%@/%@", IP_ADDR, PORT, result];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
}];
}
- (void)readerDidCancel:(QRCodeReaderViewController *)reader
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment