Add onReset() to plugins on iOS.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/4fe0e8b2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/4fe0e8b2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/4fe0e8b2 Branch: refs/heads/master Commit: 4fe0e8b291c2bae6509f7c5df4c1b5900b1c8894 Parents: 1dd9b33 Author: Braden Shepherdson <bra...@chromium.org> Authored: Fri Sep 21 11:31:23 2012 -0400 Committer: Braden Shepherdson <bra...@chromium.org> Committed: Fri Sep 21 11:31:23 2012 -0400 ---------------------------------------------------------------------- CordovaLib/Classes/CDVPlugin.h | 2 ++ CordovaLib/Classes/CDVPlugin.m | 14 ++++++++++++-- CordovaLib/Classes/CDVViewController.m | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/4fe0e8b2/CordovaLib/Classes/CDVPlugin.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVPlugin.h b/CordovaLib/Classes/CDVPlugin.h index edb8b6f..2af034f 100644 --- a/CordovaLib/Classes/CDVPlugin.h +++ b/CordovaLib/Classes/CDVPlugin.h @@ -24,6 +24,7 @@ #import "CDVCommandDelegate.h" #define CDVPluginHandleOpenURLNotification @"CDVPluginHandleOpenURLNotification" +#define CDVPluginResetNotification @"CDVPluginResetNotification" @interface CDVPlugin : NSObject { } @@ -41,6 +42,7 @@ - (void) handleOpenURL:(NSNotification*)notification; - (void) onAppTerminate; - (void) onMemoryWarning; +- (void) onReset; /* // see initWithWebView implementation http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/4fe0e8b2/CordovaLib/Classes/CDVPlugin.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVPlugin.m b/CordovaLib/Classes/CDVPlugin.m index c14f72c..ea813cf 100644 --- a/CordovaLib/Classes/CDVPlugin.m +++ b/CordovaLib/Classes/CDVPlugin.m @@ -47,7 +47,9 @@ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppTerminate) name:UIApplicationWillTerminateNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:CDVPluginHandleOpenURLNotification object:nil]; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReset) name:CDVPluginResetNotification object:nil]; + + NSLog(@"Plugin loaded"); self.webView = theWebView; // You can listen to more app notifications, see: @@ -74,6 +76,7 @@ /* NOTE: calls into JavaScript must not call or trigger any blocking UI, like alerts */ - (void) handleOpenURL:(NSNotification*)notification { + NSLog(@"handleOpenURL"); // override to handle urls sent to your app // register your url schemes in your App-Info.plist @@ -94,11 +97,18 @@ // override to remove caches, etc } +- (void) onReset +{ + // Override to cancel any long-running requests when the WebView navigates or refreshes. +} + - (void) dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:CDVPluginHandleOpenURLNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:CDVPluginResetNotification object:nil]; + /* [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil]; @@ -127,4 +137,4 @@ return [self writeJavascript:[NSString stringWithFormat:@"setTimeout(function() { %@; }, 0);", [pluginResult toErrorCallbackString:callbackId]]]; } -@end \ No newline at end of file +@end http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/4fe0e8b2/CordovaLib/Classes/CDVViewController.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m index f7a2054..027c05b 100644 --- a/CordovaLib/Classes/CDVViewController.m +++ b/CordovaLib/Classes/CDVViewController.m @@ -477,6 +477,7 @@ */ - (void) webViewDidStartLoad:(UIWebView*)theWebView { + [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginResetNotification object:nil]]; } /**