Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

CDVPlugin.m 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. #import "CDVPlugin.h"
  18. #import "CDVPlugin+Private.h"
  19. #import "CDVPlugin+Resources.h"
  20. #import "CDVViewController.h"
  21. #include <objc/message.h>
  22. @implementation UIView (org_apache_cordova_UIView_Extension)
  23. @dynamic scrollView;
  24. - (UIScrollView*)scrollView
  25. {
  26. SEL scrollViewSelector = NSSelectorFromString(@"scrollView");
  27. if ([self respondsToSelector:scrollViewSelector]) {
  28. return ((id (*)(id, SEL))objc_msgSend)(self, scrollViewSelector);
  29. }
  30. return nil;
  31. }
  32. @end
  33. NSString* const CDVPageDidLoadNotification = @"CDVPageDidLoadNotification";
  34. NSString* const CDVPluginHandleOpenURLNotification = @"CDVPluginHandleOpenURLNotification";
  35. NSString* const CDVPluginHandleOpenURLWithAppSourceAndAnnotationNotification = @"CDVPluginHandleOpenURLWithAppSourceAndAnnotationNotification";
  36. NSString* const CDVPluginResetNotification = @"CDVPluginResetNotification";
  37. NSString* const CDVViewWillAppearNotification = @"CDVViewWillAppearNotification";
  38. NSString* const CDVViewDidAppearNotification = @"CDVViewDidAppearNotification";
  39. NSString* const CDVViewWillDisappearNotification = @"CDVViewWillDisappearNotification";
  40. NSString* const CDVViewDidDisappearNotification = @"CDVViewDidDisappearNotification";
  41. NSString* const CDVViewWillLayoutSubviewsNotification = @"CDVViewWillLayoutSubviewsNotification";
  42. NSString* const CDVViewDidLayoutSubviewsNotification = @"CDVViewDidLayoutSubviewsNotification";
  43. NSString* const CDVViewWillTransitionToSizeNotification = @"CDVViewWillTransitionToSizeNotification";
  44. @interface CDVPlugin ()
  45. @property (readwrite, assign) BOOL hasPendingOperation;
  46. @property (nonatomic, readwrite, weak) id <CDVWebViewEngineProtocol> webViewEngine;
  47. @end
  48. @implementation CDVPlugin
  49. @synthesize webViewEngine, viewController, commandDelegate, hasPendingOperation;
  50. @dynamic webView;
  51. // Do not override these methods. Use pluginInitialize instead.
  52. - (instancetype)initWithWebViewEngine:(id <CDVWebViewEngineProtocol>)theWebViewEngine
  53. {
  54. self = [super init];
  55. if (self) {
  56. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppTerminate) name:UIApplicationWillTerminateNotification object:nil];
  57. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
  58. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:CDVPluginHandleOpenURLNotification object:nil];
  59. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURLWithApplicationSourceAndAnnotation:) name:CDVPluginHandleOpenURLWithAppSourceAndAnnotationNotification object:nil];
  60. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReset) name:CDVPluginResetNotification object:theWebViewEngine.engineWebView];
  61. self.webViewEngine = theWebViewEngine;
  62. }
  63. return self;
  64. }
  65. - (void)pluginInitialize
  66. {
  67. // You can listen to more app notifications, see:
  68. // http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006728-CH3-DontLinkElementID_4
  69. // NOTE: if you want to use these, make sure you uncomment the corresponding notification handler
  70. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onPause) name:UIApplicationDidEnterBackgroundNotification object:nil];
  71. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResume) name:UIApplicationWillEnterForegroundNotification object:nil];
  72. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onOrientationWillChange) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
  73. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onOrientationDidChange) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
  74. // Added in 2.5.0
  75. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pageDidLoad:) name:CDVPageDidLoadNotification object:self.webView];
  76. //Added in 4.3.0
  77. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillAppear:) name:CDVViewWillAppearNotification object:nil];
  78. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidAppear:) name:CDVViewDidAppearNotification object:nil];
  79. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillDisappear:) name:CDVViewWillDisappearNotification object:nil];
  80. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidDisappear:) name:CDVViewDidDisappearNotification object:nil];
  81. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillLayoutSubviews:) name:CDVViewWillLayoutSubviewsNotification object:nil];
  82. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidLayoutSubviews:) name:CDVViewDidLayoutSubviewsNotification object:nil];
  83. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillTransitionToSize:) name:CDVViewWillTransitionToSizeNotification object:nil];
  84. }
  85. - (void)dispose
  86. {
  87. viewController = nil;
  88. commandDelegate = nil;
  89. }
  90. - (UIView*)webView
  91. {
  92. if (self.webViewEngine != nil) {
  93. return self.webViewEngine.engineWebView;
  94. }
  95. return nil;
  96. }
  97. /*
  98. // NOTE: for onPause and onResume, calls into JavaScript must not call or trigger any blocking UI, like alerts
  99. - (void) onPause {}
  100. - (void) onResume {}
  101. - (void) onOrientationWillChange {}
  102. - (void) onOrientationDidChange {}
  103. */
  104. /* NOTE: calls into JavaScript must not call or trigger any blocking UI, like alerts */
  105. - (void)handleOpenURL:(NSNotification*)notification
  106. {
  107. // override to handle urls sent to your app
  108. // register your url schemes in your App-Info.plist
  109. NSURL* url = [notification object];
  110. if ([url isKindOfClass:[NSURL class]]) {
  111. /* Do your thing! */
  112. }
  113. }
  114. /*
  115. NOTE: calls into JavaScript must not call or trigger any blocking UI, like alerts
  116. */
  117. - (void)handleOpenURLWithApplicationSourceAndAnnotation: (NSNotification*)notification
  118. {
  119. // override to handle urls sent to your app
  120. // register your url schemes in your App-Info.plist
  121. // The notification object is an NSDictionary which contains
  122. // - url which is a type of NSURL
  123. // - sourceApplication which is a type of NSString and represents the package
  124. // id of the app that calls our app
  125. // - annotation which a type of Property list which can be several different types
  126. // please see https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/PropertyList.html
  127. NSDictionary* notificationData = [notification object];
  128. if ([notificationData isKindOfClass: NSDictionary.class]){
  129. NSURL* url = notificationData[@"url"];
  130. NSString* sourceApplication = notificationData[@"sourceApplication"];
  131. id annotation = notificationData[@"annotation"];
  132. if ([url isKindOfClass:NSURL.class] && [sourceApplication isKindOfClass:NSString.class] && annotation) {
  133. /* Do your thing! */
  134. }
  135. }
  136. }
  137. /* NOTE: calls into JavaScript must not call or trigger any blocking UI, like alerts */
  138. - (void)onAppTerminate
  139. {
  140. // override this if you need to do any cleanup on app exit
  141. }
  142. - (void)onMemoryWarning
  143. {
  144. // override to remove caches, etc
  145. }
  146. - (void)onReset
  147. {
  148. // Override to cancel any long-running requests when the WebView navigates or refreshes.
  149. }
  150. - (void)dealloc
  151. {
  152. [[NSNotificationCenter defaultCenter] removeObserver:self]; // this will remove all notifications unless added using addObserverForName:object:queue:usingBlock:
  153. }
  154. - (id)appDelegate
  155. {
  156. return [[UIApplication sharedApplication] delegate];
  157. }
  158. @end