{"action":"created","comment":{"url":"https://api.github.com/repos/ua-apps/uz-tickets/pulls/comments/31427479","id":31427479,"diff_hunk":"@@ -0,0 +1,180 @@\n+//\n+//  UZTScanViewController.m\n+//  UZTickets\n+//\n+//  Created by nekoi on 6/1/15.\n+//  Copyright (c) 2015 DAloG ltd. All rights reserved.\n+//\n+\n+#import \"UZTScanViewController.h\"\n+#import \"UZTScanView.h\"\n+\n+@interface UZTScanViewController ()<AVCaptureMetadataOutputObjectsDelegate>\n+\n+@property UZTScanView* view;\n+@property (strong) AVCaptureMetadataOutput* output;\n+@property (strong) AVCaptureSession* session;\n+@property (strong) dispatch_queue_t dispatchQueue;\n+\n+@end\n+\n+@implementation UZTScanViewController\n+@dynamic view;\n+\n++ (BOOL)canScan\n+{\n+    NSArray* devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];\n+    if (devices.count == 0) return NO;\n+    \n+    AVCaptureDevice* device;\n+    \n+    for (AVCaptureDevice* cameraDevice in devices)\n+    {\n+        if (cameraDevice.position == AVCaptureDevicePositionBack)\n+        {\n+            device = cameraDevice;\n+            break;\n+        }\n+    }\n+    \n+    if (device == nil) return NO;\n+    \n+    NSError* inputError;\n+    AVCaptureDeviceInput* input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&inputError];\n+    NSAssert(inputError == nil, @\"An error occurred while try get AVCaptureDeviceInput: %@\", inputError);\n+    if (inputError != nil) return NO;\n+    \n+    AVCaptureSession* session = [AVCaptureSession new];\n+    if (![session canAddInput:input]) return NO;\n+    \n+    return YES;\n+}\n+\n+- (void)setupLayerSessionWithAvailableObjects:(NSArray*)availableObjectTypes\n+{\n+    [self.viewModel didStartInitializingScanView];\n+    \n+    self.dispatchQueue = dispatch_queue_create(\"UZTScanQueue\", DISPATCH_QUEUE_SERIAL);\n+    \n+    dispatch_async(self.dispatchQueue, ^{\n+        NSArray* devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];\n+        NSAssert(devices.count > 0, @\"There are no device that can capture video input installed on this device\");\n+        \n+        AVCaptureSession* session = [AVCaptureSession new];\n+        self.session = session;\n+        \n+        AVCaptureMetadataOutput* output = [AVCaptureMetadataOutput new];\n+        [output setMetadataObjectsDelegate:self queue:self.dispatchQueue];\n+        output.metadataObjectTypes = nil;\n+        self.output = output;\n+        \n+        AVCaptureDevice* device;\n+        \n+        for (AVCaptureDevice* cameraDevice in devices)\n+        {\n+            if (cameraDevice.position == AVCaptureDevicePositionBack)\n+            {\n+                device = cameraDevice;\n+                if ([device hasTorch] && [device isTorchModeSupported:AVCaptureTorchModeAuto])\n+                {\n+                    NSError *error = nil;\n+                    if ([device lockForConfiguration:&error])\n+                    {\n+                        device.torchMode = AVCaptureTorchModeAuto;\n+                        [device unlockForConfiguration];\n+                    }\n+                    NSAssert(error == nil, @\"lock for configuration failed with error: %@\", error);\n+                }\n+                break;\n+            }\n+        }\n+        NSAssert(device != nil, @\"There is no back camera available on this device\");\n+        \n+        NSError* inputError;\n+        AVCaptureDeviceInput* input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&inputError];\n+        NSAssert(inputError == nil, @\"An error occurred while try get AVCaptureDeviceInput: %@\", inputError);\n+        \n+        [self.session beginConfiguration];\n+        NSAssert([session canAddInput:input], @\"Can't add camera device input to session\");\n+        [session addInput:input];\n+        \n+        NSAssert([session canAddOutput:output], @\"Can't add barcode recognition media output\");\n+        [session addOutput:output];\n+        \n+        NSSet* availableOutputObjectTypes = [NSSet setWithArray:output.availableMetadataObjectTypes];\n+        NSSet* filterObjectTypes = [NSSet setWithArray:availableObjectTypes];\n+        NSAssert([filterObjectTypes isSubsetOfSet:availableOutputObjectTypes], @\"There are object types that can't be handled\");\n+        \n+        output.metadataObjectTypes = availableObjectTypes;\n+        [self.session commitConfiguration];\n+        \n+        [self.viewModel didInitializeScanView];\n+    });\n+}\n+\n+- (void)viewDidLoad\n+{\n+    [super viewDidLoad];\n+    \n+    self.viewModel = [UZTScanViewModel new];","path":"iOS/UZTickets/src/scan/UZTScanViewController.m","position":120,"original_position":119,"commit_id":"398a99c318aed10f66b285ab6c97f2b684aeb63c","original_commit_id":"769df7fe0f8d0c5edde33efdffe554bb59134ff3","user":{"login":"xNekOIx","id":1261471,"avatar_url":"https://avatars.githubusercontent.com/u/1261471?v=3","gravatar_id":"","url":"https://api.github.com/users/xNekOIx","html_url":"https://github.com/xNekOIx","followers_url":"https://api.github.com/users/xNekOIx/followers","following_url":"https://api.github.com/users/xNekOIx/following{/other_user}","gists_url":"https://api.github.com/users/xNekOIx/gists{/gist_id}","starred_url":"https://api.github.com/users/xNekOIx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xNekOIx/subscriptions","organizations_url":"https://api.github.com/users/xNekOIx/orgs","repos_url":"https://api.github.com/users/xNekOIx/repos","events_url":"https://api.github.com/users/xNekOIx/events{/privacy}","received_events_url":"https://api.github.com/users/xNekOIx/received_events","type":"User","site_admin":false},"body":"It is. This will be removed as soon as will be implemented viewmodel injection from storyboard mechanism.","created_at":"2015-06-01T14:01:24Z","updated_at":"2015-06-01T14:01:24Z","html_url":"https://github.com/ua-apps/uz-tickets/pull/5#discussion_r31427479","pull_request_url":"https://api.github.com/repos/ua-apps/uz-tickets/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/ua-apps/uz-tickets/pulls/comments/31427479"},"html":{"href":"https://github.com/ua-apps/uz-tickets/pull/5#discussion_r31427479"},"pull_request":{"href":"https://api.github.com/repos/ua-apps/uz-tickets/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/ua-apps/uz-tickets/pulls/5","id":36627091,"html_url":"https://github.com/ua-apps/uz-tickets/pull/5","diff_url":"https://github.com/ua-apps/uz-tickets/pull/5.diff","patch_url":"https://github.com/ua-apps/uz-tickets/pull/5.patch","issue_url":"https://api.github.com/repos/ua-apps/uz-tickets/issues/5","number":5,"state":"open","locked":false,"title":"Scan code","user":{"login":"xNekOIx","id":1261471,"avatar_url":"https://avatars.githubusercontent.com/u/1261471?v=3","gravatar_id":"","url":"https://api.github.com/users/xNekOIx","html_url":"https://github.com/xNekOIx","followers_url":"https://api.github.com/users/xNekOIx/followers","following_url":"https://api.github.com/users/xNekOIx/following{/other_user}","gists_url":"https://api.github.com/users/xNekOIx/gists{/gist_id}","starred_url":"https://api.github.com/users/xNekOIx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xNekOIx/subscriptions","organizations_url":"https://api.github.com/users/xNekOIx/orgs","repos_url":"https://api.github.com/users/xNekOIx/repos","events_url":"https://api.github.com/users/xNekOIx/events{/privacy}","received_events_url":"https://api.github.com/users/xNekOIx/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-06-01T13:12:53Z","updated_at":"2015-06-01T14:01:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0599e5e01316a3ce3f85ffd73cb480bd25a97e75","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ua-apps/uz-tickets/pulls/5/commits","review_comments_url":"https://api.github.com/repos/ua-apps/uz-tickets/pulls/5/comments","review_comment_url":"https://api.github.com/repos/ua-apps/uz-tickets/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ua-apps/uz-tickets/issues/5/comments","statuses_url":"https://api.github.com/repos/ua-apps/uz-tickets/statuses/398a99c318aed10f66b285ab6c97f2b684aeb63c","head":{"label":"ua-apps:feature/scan-code","ref":"feature/scan-code","sha":"398a99c318aed10f66b285ab6c97f2b684aeb63c","user":{"login":"ua-apps","id":5416117,"avatar_url":"https://avatars.githubusercontent.com/u/5416117?v=3","gravatar_id":"","url":"https://api.github.com/users/ua-apps","html_url":"https://github.com/ua-apps","followers_url":"https://api.github.com/users/ua-apps/followers","following_url":"https://api.github.com/users/ua-apps/following{/other_user}","gists_url":"https://api.github.com/users/ua-apps/gists{/gist_id}","starred_url":"https://api.github.com/users/ua-apps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ua-apps/subscriptions","organizations_url":"https://api.github.com/users/ua-apps/orgs","repos_url":"https://api.github.com/users/ua-apps/repos","events_url":"https://api.github.com/users/ua-apps/events{/privacy}","received_events_url":"https://api.github.com/users/ua-apps/received_events","type":"Organization","site_admin":false},"repo":{"id":12695865,"name":"uz-tickets","full_name":"ua-apps/uz-tickets","owner":{"login":"ua-apps","id":5416117,"avatar_url":"https://avatars.githubusercontent.com/u/5416117?v=3","gravatar_id":"","url":"https://api.github.com/users/ua-apps","html_url":"https://github.com/ua-apps","followers_url":"https://api.github.com/users/ua-apps/followers","following_url":"https://api.github.com/users/ua-apps/following{/other_user}","gists_url":"https://api.github.com/users/ua-apps/gists{/gist_id}","starred_url":"https://api.github.com/users/ua-apps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ua-apps/subscriptions","organizations_url":"https://api.github.com/users/ua-apps/orgs","repos_url":"https://api.github.com/users/ua-apps/repos","events_url":"https://api.github.com/users/ua-apps/events{/privacy}","received_events_url":"https://api.github.com/users/ua-apps/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ua-apps/uz-tickets","description":"Free app for Android and iOS for managing tickets for Ukraine train system.","fork":false,"url":"https://api.github.com/repos/ua-apps/uz-tickets","forks_url":"https://api.github.com/repos/ua-apps/uz-tickets/forks","keys_url":"https://api.github.com/repos/ua-apps/uz-tickets/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ua-apps/uz-tickets/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ua-apps/uz-tickets/teams","hooks_url":"https://api.github.com/repos/ua-apps/uz-tickets/hooks","issue_events_url":"https://api.github.com/repos/ua-apps/uz-tickets/issues/events{/number}","events_url":"https://api.github.com/repos/ua-apps/uz-tickets/events","assignees_url":"https://api.github.com/repos/ua-apps/uz-tickets/assignees{/user}","branches_url":"https://api.github.com/repos/ua-apps/uz-tickets/branches{/branch}","tags_url":"https://api.github.com/repos/ua-apps/uz-tickets/tags","blobs_url":"https://api.github.com/repos/ua-apps/uz-tickets/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ua-apps/uz-tickets/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ua-apps/uz-tickets/git/refs{/sha}","trees_url":"https://api.github.com/repos/ua-apps/uz-tickets/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ua-apps/uz-tickets/statuses/{sha}","languages_url":"https://api.github.com/repos/ua-apps/uz-tickets/languages","stargazers_url":"https://api.github.com/repos/ua-apps/uz-tickets/stargazers","contributors_url":"https://api.github.com/repos/ua-apps/uz-tickets/contributors","subscribers_url":"https://api.github.com/repos/ua-apps/uz-tickets/subscribers","subscription_url":"https://api.github.com/repos/ua-apps/uz-tickets/subscription","commits_url":"https://api.github.com/repos/ua-apps/uz-tickets/commits{/sha}","git_commits_url":"https://api.github.com/repos/ua-apps/uz-tickets/git/commits{/sha}","comments_url":"https://api.github.com/repos/ua-apps/uz-tickets/comments{/number}","issue_comment_url":"https://api.github.com/repos/ua-apps/uz-tickets/issues/comments{/number}","contents_url":"https://api.github.com/repos/ua-apps/uz-tickets/contents/{+path}","compare_url":"https://api.github.com/repos/ua-apps/uz-tickets/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ua-apps/uz-tickets/merges","archive_url":"https://api.github.com/repos/ua-apps/uz-tickets/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ua-apps/uz-tickets/downloads","issues_url":"https://api.github.com/repos/ua-apps/uz-tickets/issues{/number}","pulls_url":"https://api.github.com/repos/ua-apps/uz-tickets/pulls{/number}","milestones_url":"https://api.github.com/repos/ua-apps/uz-tickets/milestones{/number}","notifications_url":"https://api.github.com/repos/ua-apps/uz-tickets/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ua-apps/uz-tickets/labels{/name}","releases_url":"https://api.github.com/repos/ua-apps/uz-tickets/releases{/id}","created_at":"2013-09-09T07:48:16Z","updated_at":"2015-06-01T09:10:23Z","pushed_at":"2015-06-01T13:53:36Z","git_url":"git://github.com/ua-apps/uz-tickets.git","ssh_url":"git@github.com:ua-apps/uz-tickets.git","clone_url":"https://github.com/ua-apps/uz-tickets.git","svn_url":"https://github.com/ua-apps/uz-tickets","homepage":null,"size":96,"stargazers_count":1,"watchers_count":1,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":1,"default_branch":"master"}},"base":{"label":"ua-apps:master","ref":"master","sha":"f0eab237d15fe26017d3b8c1814a558e63b6609d","user":{"login":"ua-apps","id":5416117,"avatar_url":"https://avatars.githubusercontent.com/u/5416117?v=3","gravatar_id":"","url":"https://api.github.com/users/ua-apps","html_url":"https://github.com/ua-apps","followers_url":"https://api.github.com/users/ua-apps/followers","following_url":"https://api.github.com/users/ua-apps/following{/other_user}","gists_url":"https://api.github.com/users/ua-apps/gists{/gist_id}","starred_url":"https://api.github.com/users/ua-apps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ua-apps/subscriptions","organizations_url":"https://api.github.com/users/ua-apps/orgs","repos_url":"https://api.github.com/users/ua-apps/repos","events_url":"https://api.github.com/users/ua-apps/events{/privacy}","received_events_url":"https://api.github.com/users/ua-apps/received_events","type":"Organization","site_admin":false},"repo":{"id":12695865,"name":"uz-tickets","full_name":"ua-apps/uz-tickets","owner":{"login":"ua-apps","id":5416117,"avatar_url":"https://avatars.githubusercontent.com/u/5416117?v=3","gravatar_id":"","url":"https://api.github.com/users/ua-apps","html_url":"https://github.com/ua-apps","followers_url":"https://api.github.com/users/ua-apps/followers","following_url":"https://api.github.com/users/ua-apps/following{/other_user}","gists_url":"https://api.github.com/users/ua-apps/gists{/gist_id}","starred_url":"https://api.github.com/users/ua-apps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ua-apps/subscriptions","organizations_url":"https://api.github.com/users/ua-apps/orgs","repos_url":"https://api.github.com/users/ua-apps/repos","events_url":"https://api.github.com/users/ua-apps/events{/privacy}","received_events_url":"https://api.github.com/users/ua-apps/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ua-apps/uz-tickets","description":"Free app for Android and iOS for managing tickets for Ukraine train system.","fork":false,"url":"https://api.github.com/repos/ua-apps/uz-tickets","forks_url":"https://api.github.com/repos/ua-apps/uz-tickets/forks","keys_url":"https://api.github.com/repos/ua-apps/uz-tickets/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ua-apps/uz-tickets/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ua-apps/uz-tickets/teams","hooks_url":"https://api.github.com/repos/ua-apps/uz-tickets/hooks","issue_events_url":"https://api.github.com/repos/ua-apps/uz-tickets/issues/events{/number}","events_url":"https://api.github.com/repos/ua-apps/uz-tickets/events","assignees_url":"https://api.github.com/repos/ua-apps/uz-tickets/assignees{/user}","branches_url":"https://api.github.com/repos/ua-apps/uz-tickets/branches{/branch}","tags_url":"https://api.github.com/repos/ua-apps/uz-tickets/tags","blobs_url":"https://api.github.com/repos/ua-apps/uz-tickets/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ua-apps/uz-tickets/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ua-apps/uz-tickets/git/refs{/sha}","trees_url":"https://api.github.com/repos/ua-apps/uz-tickets/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ua-apps/uz-tickets/statuses/{sha}","languages_url":"https://api.github.com/repos/ua-apps/uz-tickets/languages","stargazers_url":"https://api.github.com/repos/ua-apps/uz-tickets/stargazers","contributors_url":"https://api.github.com/repos/ua-apps/uz-tickets/contributors","subscribers_url":"https://api.github.com/repos/ua-apps/uz-tickets/subscribers","subscription_url":"https://api.github.com/repos/ua-apps/uz-tickets/subscription","commits_url":"https://api.github.com/repos/ua-apps/uz-tickets/commits{/sha}","git_commits_url":"https://api.github.com/repos/ua-apps/uz-tickets/git/commits{/sha}","comments_url":"https://api.github.com/repos/ua-apps/uz-tickets/comments{/number}","issue_comment_url":"https://api.github.com/repos/ua-apps/uz-tickets/issues/comments{/number}","contents_url":"https://api.github.com/repos/ua-apps/uz-tickets/contents/{+path}","compare_url":"https://api.github.com/repos/ua-apps/uz-tickets/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ua-apps/uz-tickets/merges","archive_url":"https://api.github.com/repos/ua-apps/uz-tickets/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ua-apps/uz-tickets/downloads","issues_url":"https://api.github.com/repos/ua-apps/uz-tickets/issues{/number}","pulls_url":"https://api.github.com/repos/ua-apps/uz-tickets/pulls{/number}","milestones_url":"https://api.github.com/repos/ua-apps/uz-tickets/milestones{/number}","notifications_url":"https://api.github.com/repos/ua-apps/uz-tickets/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ua-apps/uz-tickets/labels{/name}","releases_url":"https://api.github.com/repos/ua-apps/uz-tickets/releases{/id}","created_at":"2013-09-09T07:48:16Z","updated_at":"2015-06-01T09:10:23Z","pushed_at":"2015-06-01T13:53:36Z","git_url":"git://github.com/ua-apps/uz-tickets.git","ssh_url":"git@github.com:ua-apps/uz-tickets.git","clone_url":"https://github.com/ua-apps/uz-tickets.git","svn_url":"https://github.com/ua-apps/uz-tickets","homepage":null,"size":96,"stargazers_count":1,"watchers_count":1,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ua-apps/uz-tickets/pulls/5"},"html":{"href":"https://github.com/ua-apps/uz-tickets/pull/5"},"issue":{"href":"https://api.github.com/repos/ua-apps/uz-tickets/issues/5"},"comments":{"href":"https://api.github.com/repos/ua-apps/uz-tickets/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/ua-apps/uz-tickets/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/ua-apps/uz-tickets/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ua-apps/uz-tickets/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/ua-apps/uz-tickets/statuses/398a99c318aed10f66b285ab6c97f2b684aeb63c"}}}}