You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2013/01/12 02:12:06 UTC
ios commit: [CB-2159] handleOpenURL not called on iOS
Updated Branches:
refs/heads/master 08edbc329 -> 518318377
[CB-2159] handleOpenURL not called on iOS
Note that for backgrounded apps, it still needs the explicit JavaScript write in AppDelegate.m (to fix later)
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/51831837
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/51831837
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/51831837
Branch: refs/heads/master
Commit: 51831837765bf2673ac903bf5bd60acc5653fbcc
Parents: 08edbc3
Author: Shazron Abdullah <sh...@apache.org>
Authored: Fri Jan 11 17:11:59 2013 -0800
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Fri Jan 11 17:11:59 2013 -0800
----------------------------------------------------------------------
CordovaLib/Classes/CDVViewController.m | 25 ++++++++++++++++++++++++-
1 files changed, 24 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/51831837/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m
index 43564b5..abdfcc7 100644
--- a/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/Classes/CDVViewController.m
@@ -43,6 +43,8 @@ static NSString* gOriginalUserAgent = nil;
@property (nonatomic, readwrite, strong) UIImageView* imageView;
@property (readwrite, assign) BOOL initialized;
+@property (atomic, strong) NSURL* openURL;
+
@end
@implementation CDVViewController
@@ -51,7 +53,7 @@ static NSString* gOriginalUserAgent = nil;
@synthesize pluginObjects, pluginsMap, whitelist;
@synthesize configParser, settings, loadFromString;
@synthesize imageView, activityView, useSplashScreen;
-@synthesize wwwFolderName, startPage, initialized;
+@synthesize wwwFolderName, startPage, initialized, openURL;
@synthesize commandDelegate = _commandDelegate;
@synthesize commandQueue = _commandQueue;
@@ -76,6 +78,7 @@ static NSString* gOriginalUserAgent = nil;
name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:CDVPluginHandleOpenURLNotification object:nil];
// read from UISupportedInterfaceOrientations (or UISupportedInterfaceOrientations~iPad, if its iPad) from -Info.plist
self.supportedOrientations = [self parseInterfaceOrientations:
@@ -544,6 +547,8 @@ static NSString* gOriginalUserAgent = nil;
// The _nativeReady = true; is used when this is run before cordova.js is loaded.
NSString* nativeReady = @"try{cordova.require('cordova/channel').onNativeReady.fire();}catch(e){window._nativeReady = true;}";
[self.commandDelegate evalJs:nativeReady];
+
+ [self processOpenUrl];
}
- (void)webView:(UIWebView*)webView didFailLoadWithError:(NSError*)error
@@ -947,6 +952,23 @@ BOOL gSplashScreenShown = NO;
// ///////////////////////
+- (void)handleOpenURL:(NSNotification*)notification
+{
+ self.openURL = notification.object;
+}
+
+- (void)processOpenUrl
+{
+ if (self.openURL) {
+ // calls into javascript global function 'handleOpenURL'
+ NSString* jsString = [NSString stringWithFormat:@"handleOpenURL(\"%@\");", [self.openURL description]];
+ [self.webView stringByEvaluatingJavaScriptFromString:jsString];
+ self.openURL = nil;
+ }
+}
+
+// ///////////////////////
+
- (void)dealloc
{
[CDVURLProtocol unregisterViewController:self];
@@ -956,6 +978,7 @@ BOOL gSplashScreenShown = NO;
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSCurrentLocaleDidChangeNotification object:nil];
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:CDVPluginHandleOpenURLNotification object:nil];
self.webView.delegate = nil;
self.webView = nil;