1 | // |
---|
2 | // AppDelegate.m |
---|
3 | // Piwigo |
---|
4 | // |
---|
5 | // Created by Patrice Gauchon on 01/10/11. |
---|
6 | // Copyright __MyCompanyName__ 2011. All rights reserved. |
---|
7 | // |
---|
8 | |
---|
9 | #import "AppDelegate.h" |
---|
10 | #ifdef PHONEGAP_FRAMEWORK |
---|
11 | #import <PhoneGap/PhoneGapViewController.h> |
---|
12 | #else |
---|
13 | #import "PhoneGapViewController.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | @implementation AppDelegate |
---|
17 | |
---|
18 | @synthesize invokeString; |
---|
19 | |
---|
20 | - (id) init |
---|
21 | { |
---|
22 | /** If you need to do any extra app-specific initialization, you can do it here |
---|
23 | * -jm |
---|
24 | **/ |
---|
25 | return [super init]; |
---|
26 | } |
---|
27 | |
---|
28 | /** |
---|
29 | * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up) |
---|
30 | */ |
---|
31 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions |
---|
32 | { |
---|
33 | |
---|
34 | NSArray *keyArray = [launchOptions allKeys]; |
---|
35 | if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil) |
---|
36 | { |
---|
37 | NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]]; |
---|
38 | self.invokeString = [url absoluteString]; |
---|
39 | NSLog(@"Piwigo launchOptions = %@",url); |
---|
40 | } |
---|
41 | |
---|
42 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; |
---|
43 | } |
---|
44 | |
---|
45 | // this happens while we are running ( in the background, or from within our own app ) |
---|
46 | // only valid if Piwigo.plist specifies a protocol to handle |
---|
47 | - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url |
---|
48 | { |
---|
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]; |
---|
52 | } |
---|
53 | |
---|
54 | -(id) getCommandInstance:(NSString*)className |
---|
55 | { |
---|
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 |
---|
58 | **/ |
---|
59 | return [super getCommandInstance:className]; |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | Called when the webview finishes loading. This stops the activity view and closes the imageview |
---|
64 | */ |
---|
65 | - (void)webViewDidFinishLoad:(UIWebView *)theWebView |
---|
66 | { |
---|
67 | // only valid if Piwigo.plist specifies a protocol to handle |
---|
68 | if(self.invokeString) |
---|
69 | { |
---|
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]; |
---|
73 | } |
---|
74 | return [ super webViewDidFinishLoad:theWebView ]; |
---|
75 | } |
---|
76 | |
---|
77 | - (void)webViewDidStartLoad:(UIWebView *)theWebView |
---|
78 | { |
---|
79 | return [ super webViewDidStartLoad:theWebView ]; |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * Fail Loading With Error |
---|
84 | * Error - If the webpage failed to load display an error with the reason. |
---|
85 | */ |
---|
86 | - (void)webView:(UIWebView *)theWebView didFailLoadWithError:(NSError *)error |
---|
87 | { |
---|
88 | return [ super webView:theWebView didFailLoadWithError:error ]; |
---|
89 | } |
---|
90 | |
---|
91 | /** |
---|
92 | * Start Loading Request |
---|
93 | * This is where most of the magic happens... We take the request(s) and process the response. |
---|
94 | * From here we can re direct links and other protocalls to different internal methods. |
---|
95 | */ |
---|
96 | /* |
---|
97 | - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType |
---|
98 | { |
---|
99 | return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ]; |
---|
100 | } |
---|
101 | */ |
---|
102 | |
---|
103 | - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType |
---|
104 | { |
---|
105 | NSURL *url = [request URL]; |
---|
106 | |
---|
107 | // Intercept the external http requests and forward to Safari.app |
---|
108 | // Otherwise forward to the PhoneGap WebView |
---|
109 | if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) { |
---|
110 | [[UIApplication sharedApplication] openURL:url]; |
---|
111 | return NO; |
---|
112 | } |
---|
113 | else { |
---|
114 | return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ]; |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | - (BOOL) execute:(InvokedUrlCommand*)command |
---|
120 | { |
---|
121 | return [ super execute:command]; |
---|
122 | } |
---|
123 | |
---|
124 | - (void)dealloc |
---|
125 | { |
---|
126 | [ super dealloc ]; |
---|
127 | } |
---|
128 | |
---|
129 | @end |
---|