the very simple test app that calls the ZXingWidget
[zxing.git] / iphone / Classes / ZXingAppDelegate.m
1 //
2 //  ZXingAppDelegate.m
3 //  ZXing
4 //
5 //  Created by Christian Brunschen on 23/04/2008.
6 //
7 /*
8  * Copyright 2008 ZXing authors
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22
23
24 #import "ZXingAppDelegate.h"
25 #import "DecoderViewController.h"
26
27 @implementation ZXingAppDelegate
28
29 @synthesize window;
30 @synthesize viewController;
31 @synthesize navigationController;
32
33 - (void)applicationDidFinishLaunching:(UIApplication *)application {
34   /* create the view controller */
35   DecoderViewController *vc = 
36     [[DecoderViewController alloc] initWithNibName:@"DecoderView" 
37                                             bundle:[NSBundle mainBundle]];
38   self.viewController = vc;
39   [vc release];
40   
41   navigationController = [[UINavigationController alloc] 
42                           initWithRootViewController:viewController];
43   
44   // hook up the view controller's view to be in the window
45   [window addSubview:navigationController.view];
46   
47   // show the window
48   [window makeKeyAndVisible];
49   
50   // pick and decode using the first available source type in priority order
51   UIImagePickerControllerSourceType sourceTypes[] = {
52     UIImagePickerControllerSourceTypeCamera,
53     UIImagePickerControllerSourceTypeSavedPhotosAlbum,
54     UIImagePickerControllerSourceTypePhotoLibrary
55   };
56
57   for (int i = 0; i < sizeof(sourceTypes) / sizeof(*sourceTypes); i++) {
58     if ([UIImagePickerController isSourceTypeAvailable:sourceTypes[i]]) {
59       [viewController pickAndDecodeFromSource:sourceTypes[i]];
60       break;
61     }
62   }
63 }
64
65 - (void)dealloc {
66   [window release];
67   [super dealloc];
68 }
69
70 @end