/iOS/dodo/Classes/AppDelegate.m

https://github.com/ohdarling/dodo · Objective C · 112 lines · 61 code · 17 blank · 34 comment · 2 complexity · 07ab0837cd32c55e8b92212575c17256 MD5 · raw file

  1. //
  2. // AppDelegate.m
  3. // dodo
  4. //
  5. // Created by Xu Jiwei on 12-2-18.
  6. // Copyright xujiwei.com 2012年. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #ifdef PHONEGAP_FRAMEWORK
  10. #import <PhoneGap/PhoneGapViewController.h>
  11. #else
  12. #import "PhoneGapViewController.h"
  13. #endif
  14. @implementation AppDelegate
  15. @synthesize invokeString;
  16. - (id) init
  17. {
  18. /** If you need to do any extra app-specific initialization, you can do it here
  19. * -jm
  20. **/
  21. return [super init];
  22. }
  23. /**
  24. * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
  25. */
  26. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  27. {
  28. NSArray *keyArray = [launchOptions allKeys];
  29. if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil)
  30. {
  31. NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
  32. self.invokeString = [url absoluteString];
  33. NSLog(@"dodo launchOptions = %@",url);
  34. }
  35. return [super application:application didFinishLaunchingWithOptions:launchOptions];
  36. }
  37. // this happens while we are running ( in the background, or from within our own app )
  38. // only valid if dodo.plist specifies a protocol to handle
  39. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
  40. {
  41. // must call super so all plugins will get the notification, and their handlers will be called
  42. // super also calls into javascript global function 'handleOpenURL'
  43. return [super application:application handleOpenURL:url];
  44. }
  45. -(id) getCommandInstance:(NSString*)className
  46. {
  47. /** You can catch your own commands here, if you wanted to extend the gap: protocol, or add your
  48. * own app specific protocol to it. -jm
  49. **/
  50. return [super getCommandInstance:className];
  51. }
  52. /**
  53. Called when the webview finishes loading. This stops the activity view and closes the imageview
  54. */
  55. - (void)webViewDidFinishLoad:(UIWebView *)theWebView
  56. {
  57. // only valid if dodo.plist specifies a protocol to handle
  58. if(self.invokeString)
  59. {
  60. // this is passed before the deviceready event is fired, so you can access it in js when you receive deviceready
  61. NSString* jsString = [NSString stringWithFormat:@"var invokeString = \"%@\";", self.invokeString];
  62. [theWebView stringByEvaluatingJavaScriptFromString:jsString];
  63. }
  64. return [ super webViewDidFinishLoad:theWebView ];
  65. }
  66. - (void)webViewDidStartLoad:(UIWebView *)theWebView
  67. {
  68. return [ super webViewDidStartLoad:theWebView ];
  69. }
  70. /**
  71. * Fail Loading With Error
  72. * Error - If the webpage failed to load display an error with the reason.
  73. */
  74. - (void)webView:(UIWebView *)theWebView didFailLoadWithError:(NSError *)error
  75. {
  76. return [ super webView:theWebView didFailLoadWithError:error ];
  77. }
  78. /**
  79. * Start Loading Request
  80. * This is where most of the magic happens... We take the request(s) and process the response.
  81. * From here we can re direct links and other protocalls to different internal methods.
  82. */
  83. - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
  84. {
  85. return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
  86. }
  87. - (BOOL) execute:(InvokedUrlCommand*)command
  88. {
  89. return [ super execute:command];
  90. }
  91. - (void)dealloc
  92. {
  93. [ super dealloc ];
  94. }
  95. @end