Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 20    Views: 120

Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
08/15/14 03:03 AM (10 years ago)

Custom URL Plugin Help!!!!

I have just finished developing an app in Jquery Mobile, uploaded to my server and feed the URL into the BT Custom URL plugin. The issue I have is that I have some external links within my project, that when clicked I want it to open the phones default browser and unfortunately it doesn't open the browser, instead it opens within the app and breaks the app. How can I get the custom url plugin to open external links and open the phones default browser? Really stuck, not sure if its possible or not. Any help would be appreciated. Need a solution iOS, haven't yet tried in Android.
 
Mario @ Buzztouch
buzztouch Evangelist
Profile
Posts: 42
Reg: Nov 25, 2011
Frankfurt
10,920
like
08/15/14 03:27 AM (10 years ago)
Hi, have a look at "shouldStartLoadWithRequest" in the right viewController. Here is a sample code... -(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inNavigationType { NSLog(@"Loading a URL: %@", [[inRequest URL] absoluteString]); if ( inNavigationType == UIWebViewNavigationTypeLinkClicked ) { [[UIApplication sharedApplication] openURL:[inRequest URL]]; } } or you can use "openInSafari" too. Cheers M.
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
08/15/14 03:44 AM (10 years ago)
Hi Mario thank you for the reply, not a coder, but I will try and have a look. Can you explain, what this code does and how it will help me, if you don't mind?
 
Mario @ Buzztouch
buzztouch Evangelist
Profile
Posts: 42
Reg: Nov 25, 2011
Frankfurt
10,920
like
08/15/14 03:47 AM (10 years ago)
This opens a clicked link into safari.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
08/15/14 03:51 AM (10 years ago)
Yo dudes, I was dining out last night, but this is the method I was exploring. It has to initially load but tehn not again if that makes sense, everytime a link is clicked the webview thinks it's leaving the page but it's actually loading part of the web application.
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
08/15/14 03:58 AM (10 years ago)
OK, will I'm going to attempt to try this solution, thanks guys, fingers crossed as I have no idea what I am doing. Kittsy, is it also possible to stop the Custom URL plugin from refreshing every time I navigate through my web app?
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
08/15/14 04:04 AM (10 years ago)
yup with that line that mario gave if ( inNavigationType == UIWebViewNavigationTypeLinkClicked ) { return NO; } } In theory webview should ignore but jquery shoud still process it
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
08/15/14 04:36 AM (10 years ago)
Kittsy you have now confused me, who's code should I be using, Mario's or what you have just posted?
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
08/15/14 05:07 AM (10 years ago)
Find the line of code that Mario posted when you find a line similar to this if ( inNavigationType == UIWebViewNavigationTypeLinkClicked ) { [[UIApplication sharedApplication] openURL:[inRequest URL]]; } } swap it to this if ( inNavigationType == UIWebViewNavigationTypeLinkClicked ) { return NO; } }
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
08/15/14 05:10 AM (10 years ago)
and thats it is it?
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
08/15/14 05:20 AM (10 years ago)
possibly lol
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
08/15/14 06:51 AM (10 years ago)
Hi Guys I cannot find this line referred by Mario. Is it the BT_viewController.m or .h I should be looking. To be honest, looked at both just can't find the line I need to change.
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
08/15/14 07:09 AM (10 years ago)
Struggling! I think I've found it in the Custom URL plugin, not sure if that is where I am suppose to look. But the example codes you guys have posted, I don't see, so not sure what to do.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
08/15/14 07:20 AM (10 years ago)
I'll be home in 3 hours. email me the link and I'll knock up a sample project
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
08/15/14 07:24 AM (10 years ago)
Cheers Man! doing my head in! I'll send you an email of the URL for my project and its this I am trying to get external links to open the phones browser.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
08/15/14 07:27 AM (10 years ago)
ah I never read the full post above just think back to the text. So some links yopu want to lead out of the app others you don't want to mess transitions up
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
08/15/14 07:34 AM (10 years ago)
Sent you email to explain a bit more clearer. 1. But basically, I want to open some of the links within the web app in the phones default browser and not within the app. 2. I wanted to stop the Custom URL plugin from reloading the site every time I navigate through the web app. Because its Jquery Mobile, it loads the full site from the start and I feel its the reloading of the site every time that messes with the page transitions.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
08/15/14 02:19 PM (10 years ago)
Just thinking out loud here, but would it work if you create a screen of type 'launch native app' and you launch a browser for those links out of your web page? You can do that with html pro or using the Buzztouch url scheme (see @Niraj's howto http://www.buzztouch.com/files/howtos/BuzzTouch%20URL%20Scheme%20with%20Xcode%205.pdf)?
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
08/16/14 10:43 AM (10 years ago)
Kittsy -- when you've got it sorted out, please let us know. Looking forward to a Kittsy blog post of a tutorial! iOS and Android ? :-) Thank you, -- Niraj
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
08/16/14 11:02 AM (10 years ago)
Hi Niraj Kittsy did solve the issue for me, below is how: Here is how to open to safari with your app in customurl.m line 486 ish make the code look like this. It works by saying any link that doesn’t belong to http://project-demo-server.info will be sent to safari. //text message if([urlString rangeOfString: @"sms:" options:NSCaseInsensitiveSearch].location != NSNotFound){ if([appDelegate.rootDevice canSendSMS]){ showConfirm = 1; confirmMessage = NSLocalizedString(@"launch_sms", "Would you like to send an SMS?"); }else{ //bail return NO; } } //ask for confirmation before launching native app if(showConfirm == 1){ [self confirmLink:confirmMessage]; return NO; } //your domain stuff if([urlString rangeOfString: @"http://project-demo-server.info" options:NSCaseInsensitiveSearch].location != NSNotFound){ return YES; }else{ [[UIApplication sharedApplication] openURL:[request URL]]; return NO; } //remove this //only here if we did not click a special link //return YES; } //URL to load was empty //only here if URL was empty? return NO; } ------------------------------------------------------------------------------ And to add more than one URL Kittsy sais to do the following: add more url's just change the websites, you can add as many as you like, example below: //your domain stuff if([urlString rangeOfString: @"http://project-demo-server.info" options:NSCaseInsensitiveSearch].location != NSNotFound){ return YES; }else if ([urlString rangeOfString: @"youtube.com" options:NSCaseInsensitiveSearch].location != NSNotFound){ return YES; }else if ([urlString rangeOfString: @"whaterver.com" options:NSCaseInsensitiveSearch].location != NSNotFound){ return YES; }else if ([urlString rangeOfString: @"sausages.com" options:NSCaseInsensitiveSearch].location != NSNotFound){ return YES; }else{ [[UIApplication sharedApplication] openURL:[request URL]]; return NO; }
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
08/16/14 11:04 AM (10 years ago)
Niraj if you know how to apply the same fix for Android, that would really help as I have the same issue with the Android app version.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.