5 // Created by FNP on 10/19/11.
6 // Copyright __MyCompanyName__ 2011. All rights reserved.
9 #import "AppDelegate.h"
10 #ifdef PHONEGAP_FRAMEWORK
11 #import <PhoneGap/PhoneGapViewController.h>
13 #import "PhoneGapViewController.h"
16 @implementation AppDelegate
18 @synthesize invokeString;
22 /** If you need to do any extra app-specific initialization, you can do it here
29 * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
31 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
34 NSArray *keyArray = [launchOptions allKeys];
35 if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil)
37 NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
38 self.invokeString = [url absoluteString];
39 NSLog(@"wl-mobi launchOptions = %@",url);
42 return [super application:application didFinishLaunchingWithOptions:launchOptions];
45 // this happens while we are running ( in the background, or from within our own app )
46 // only valid if wl-mobi.plist specifies a protocol to handle
47 - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
49 // must call super so all plugins will get the notification, and their handlers will be called
50 // super also calls into javascript global function 'handleOpenURL'
51 return [super application:application handleOpenURL:url];
54 -(id) getCommandInstance:(NSString*)className
56 /** You can catch your own commands here, if you wanted to extend the gap: protocol, or add your
57 * own app specific protocol to it. -jm
59 return [super getCommandInstance:className];
63 Called when the webview finishes loading. This stops the activity view and closes the imageview
65 - (void)webViewDidFinishLoad:(UIWebView *)theWebView
67 // only valid if wl-mobi.plist specifies a protocol to handle
70 // this is passed before the deviceready event is fired, so you can access it in js when you receive deviceready
71 NSString* jsString = [NSString stringWithFormat:@"var invokeString = \"%@\";", self.invokeString];
72 [theWebView stringByEvaluatingJavaScriptFromString:jsString];
74 return [ super webViewDidFinishLoad:theWebView ];
77 - (void)webViewDidStartLoad:(UIWebView *)theWebView
79 return [ super webViewDidStartLoad:theWebView ];
83 * Fail Loading With Error
84 * Error - If the webpage failed to load display an error with the reason.
86 - (void)webView:(UIWebView *)theWebView didFailLoadWithError:(NSError *)error
88 return [ super webView:theWebView didFailLoadWithError:error ];
93 * Start Loading Request
94 * This is where most of the magic happens... We take the request(s) and process the response.
95 * From here we can re direct links and other protocalls to different internal methods.
97 - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
99 NSURL *url = [request URL];
101 // Intercept the external http requests and forward to Safari.app
102 // Otherwise forward to the PhoneGap WebView
103 if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
104 [[UIApplication sharedApplication] openURL:url];
108 return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
114 - (BOOL) execute:(InvokedUrlCommand*)command
116 return [ super execute:command];
125 + (NSString*) startPage
127 return @"WolneLektury.html";