2012-10-02 17:19:58 -07:00
|
|
|
// -*- mode:objc; c-basic-offset:2; indent-tabs-mode:nil -*-
|
|
|
|
/**
|
|
|
|
* Copyright 2010-2012 ZXing authors All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2010-11-14 09:18:29 -08:00
|
|
|
|
|
|
|
#import "BarcodesAppDelegate.h"
|
|
|
|
|
|
|
|
@implementation BarcodesAppDelegate
|
|
|
|
|
|
|
|
@synthesize window;
|
2010-12-22 09:35:17 -08:00
|
|
|
@synthesize tabBarController;
|
2011-12-16 06:46:58 -08:00
|
|
|
@synthesize viewController;
|
2010-11-14 09:18:29 -08:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Application lifecycle
|
|
|
|
|
2011-12-16 06:46:58 -08:00
|
|
|
- (BOOL)myOpenURL:(NSURL*)url {
|
2012-10-02 17:19:58 -07:00
|
|
|
if (!url) return NO;
|
|
|
|
if ([[url scheme] isEqualToString:@"zxing"]) {
|
|
|
|
if ([[url host] isEqualToString:@"scan"]) {
|
|
|
|
NSArray *pairs = [[url query] componentsSeparatedByString:@"&"];
|
2011-12-16 06:46:58 -08:00
|
|
|
|
2012-10-02 17:19:58 -07:00
|
|
|
for (NSString *pair in pairs) {
|
|
|
|
NSArray *elements = [pair componentsSeparatedByString:@"="];
|
|
|
|
NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
2011-12-16 06:46:58 -08:00
|
|
|
|
2012-10-02 17:19:58 -07:00
|
|
|
if ([key isEqualToString:@"ret"]) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:val forKey:@"returnURL"];
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
[[self viewController] scan:nil];
|
2011-12-16 06:46:58 -08:00
|
|
|
}
|
2012-10-02 17:19:58 -07:00
|
|
|
if ([key isEqualToString:@"SCAN_FORMATS"]) {
|
|
|
|
// Storing these, but they effect nothing yet.
|
|
|
|
NSArray *formats = [val componentsSeparatedByString:@","];
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:formats forKey:@"scanFormats"];
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
}
|
|
|
|
}
|
2011-12-16 06:46:58 -08:00
|
|
|
}
|
2012-10-02 17:19:58 -07:00
|
|
|
return YES;
|
|
|
|
} else {
|
|
|
|
return NO;
|
|
|
|
}
|
2011-12-16 06:46:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)registerView:(ZXMainViewController*)controller {
|
2012-10-02 17:19:58 -07:00
|
|
|
[self setViewController:controller];
|
2011-12-16 06:46:58 -08:00
|
|
|
}
|
|
|
|
|
2010-11-14 09:18:29 -08:00
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
|
|
|
2011-12-16 06:46:58 -08:00
|
|
|
// Check if launching from URL
|
|
|
|
NSURL *url = [launchOptions objectForKey: UIApplicationLaunchOptionsURLKey];
|
|
|
|
if ([url isMemberOfClass: [NSURL class]]) {
|
|
|
|
return [self myOpenURL: url];
|
|
|
|
} else {
|
|
|
|
// Clear the return URL so the application goes back to working as normal...
|
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"returnURL"];
|
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"scanFormats"];
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
}
|
|
|
|
|
2012-10-02 17:19:58 -07:00
|
|
|
// Override point for customization after application launch.
|
2012-10-02 17:15:48 -07:00
|
|
|
window.rootViewController = tabBarController;
|
2010-11-14 09:18:29 -08:00
|
|
|
[self.window makeKeyAndVisible];
|
2010-11-29 03:46:35 -08:00
|
|
|
|
2010-11-14 09:18:29 -08:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2011-12-16 06:46:58 -08:00
|
|
|
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
|
|
|
|
{
|
2012-10-02 17:19:58 -07:00
|
|
|
return [self myOpenURL: url];
|
2011-12-16 06:46:58 -08:00
|
|
|
}
|
2010-11-14 09:18:29 -08:00
|
|
|
|
|
|
|
- (void)applicationWillResignActive:(UIApplication *)application {
|
2012-10-02 17:19:58 -07:00
|
|
|
/*
|
|
|
|
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
|
|
|
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
|
|
|
*/
|
2010-11-14 09:18:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
2012-10-02 17:19:58 -07:00
|
|
|
/*
|
|
|
|
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
|
|
|
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
|
|
|
*/
|
2011-12-16 06:46:58 -08:00
|
|
|
|
2012-10-02 17:19:58 -07:00
|
|
|
// Clear the return URL so the application goes back to working as normal...
|
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"returnURL"];
|
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"scanFormats"];
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
2010-11-14 09:18:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
2012-10-02 17:19:58 -07:00
|
|
|
/*
|
|
|
|
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
|
|
|
*/
|
2010-11-14 09:18:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
2012-10-02 17:19:58 -07:00
|
|
|
/*
|
|
|
|
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
|
|
|
*/
|
2010-11-14 09:18:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)applicationWillTerminate:(UIApplication *)application {
|
2012-10-02 17:19:58 -07:00
|
|
|
/*
|
|
|
|
Called when the application is about to terminate.
|
|
|
|
See also applicationDidEnterBackground:.
|
|
|
|
*/
|
2010-11-14 09:18:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Memory management
|
|
|
|
|
|
|
|
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
2012-10-02 17:19:58 -07:00
|
|
|
/*
|
|
|
|
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
|
|
|
*/
|
2010-11-14 09:18:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)dealloc {
|
2010-12-22 09:35:17 -08:00
|
|
|
[tabBarController release];
|
2010-11-14 09:18:29 -08:00
|
|
|
[window release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|