Return-Path: X-Original-To: apmail-cordova-issues-archive@minotaur.apache.org Delivered-To: apmail-cordova-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EC1C1101A9 for ; Tue, 2 Dec 2014 10:20:13 +0000 (UTC) Received: (qmail 22986 invoked by uid 500); 2 Dec 2014 10:20:13 -0000 Delivered-To: apmail-cordova-issues-archive@cordova.apache.org Received: (qmail 22969 invoked by uid 500); 2 Dec 2014 10:20:13 -0000 Mailing-List: contact issues-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@cordova.apache.org Received: (qmail 22958 invoked by uid 99); 2 Dec 2014 10:20:13 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Dec 2014 10:20:13 +0000 Date: Tue, 2 Dec 2014 10:20:13 +0000 (UTC) From: "Antonio Laguna (JIRA)" To: issues@cordova.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CB-8028) handleOpenURL doesn't work properly when app is being launched for the first time MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CB-8028?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14231268#comment-14231268 ] Antonio Laguna commented on CB-8028: ------------------------------------ I reckon that's not a good solution since that function not being defined doesn't mean the page is not loaded. It may work as a workaround but not as a end to end solution. Either the {{readyState}} is {{true}} earlier than it should or that function is being called prematurely. I fixed it with a Cordova Plugin which is fairly simple and trivial. Will remove as soon as this gets fixed. {code:title=UrlHandler.h|borderStyle=solid} #import @interface UrlHandler : CDVPlugin @property (nonatomic, strong) NSURL *url; @end {code} {code:title=UrlHandler.m|borderStyle=solid} - (void)pluginInitialize { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationLaunchedWithUrl:) name:CDVPluginHandleOpenURLNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationFinishedLaunching:) name:CDVPageDidLoadNotification object:nil]; } - (void)applicationLaunchedWithUrl:(NSNotification*)notification { NSURL *url = [notification object]; self.url = url; } - (void)applicationFinishedLaunching:(NSNotification*)notification { if (self.url != nil) { NSString* jsString = [NSString stringWithFormat:@"if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");}", self.url]; [self.webView stringByEvaluatingJavaScriptFromString:jsString]; } } {code} > handleOpenURL doesn't work properly when app is being launched for the first time > --------------------------------------------------------------------------------- > > Key: CB-8028 > URL: https://issues.apache.org/jira/browse/CB-8028 > Project: Apache Cordova > Issue Type: Bug > Components: iOS > Affects Versions: 3.7.0 > Reporter: Antonio Laguna > Assignee: Shazron Abdullah > > Hi! > Please bear in mind that this is my first issue being reported here but I thought it to be worth it. > So, we've been developing a Cordova application lately and we decided to add a notification center plugin to be able to launch the application from it, taking advantage of the url-scheme on iOS. > We discovered that it worked flawlessly when it was launched and the app was in background but it wasn't when the app was closed and tried to launch from there. > So I dug deeper. > Since this is an Ionic application, I thought the issue was due to Angular not being ready at the appropriate time or something like that so I just put something really low-level which didn't depend on any library: > {code:javascript} > window.foo = 'bar'; > {code} > And then checked with a timeout (after app was ready) to see if it was there. But it wasn't. > So I dug deeper. > So the issue seems to come on this function which is on the {{CDDViewController}} class > {code} > - (void)processOpenUrl:(NSURL*)url pageLoaded:(BOOL)pageLoaded > { > if (!pageLoaded) { > // query the webview for readystate > NSString* readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"]; > pageLoaded = [readyState isEqualToString:@"loaded"] || [readyState isEqualToString:@"complete"]; > } > if (pageLoaded) { > // calls into javascript global function 'handleOpenURL' > NSString* jsString = [NSString stringWithFormat:@"if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");}", url]; > [self.webView stringByEvaluatingJavaScriptFromString:jsString]; > } else { > // save for when page has loaded > self.openURL = url; > } > } > {code} > The thing is that the second check for {{pageLoaded}} is positive even though the page is clearly at a really early stage. The Splash is still being shown and the DOM although it may be ready-ish, it doesn't work properly (clearly). > This is the flow: > * It comes first by {{(void)processOpenUrl:(NSURL*)url}} - The {{handleOpenUrl}} function is then called cause even though {{NO}} is passed as a parameter, Cordova gets to think it's ready. > * Then it comes to {{onPageDidLoad}} which would call {{(void)processOpenUrl:(NSURL*)url pageLoaded:(BOOL)pageLoaded}} too but since {{openURL}} hasn't been saved this time, it won't do anything > Just to make sure of things, I tried to {{self.openURL = url;}} even if the page was loaded and that turned out to work. > I don't understand the implications of this but IMHO, {{onPageDidLoad}} is a better point to understand wether the app is ready or not than querying the document like that cause the code doesn't seem to be there yet. > Please note that I put my handler before anything else on the header to ensure it wasn't a racing issue. -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org For additional commands, e-mail: issues-help@cordova.apache.org