Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 10    Views: 68

Rotsos
Apple Fan
Profile
Posts: 33
Reg: Jan 30, 2013
Limassol
3,430
02/13/13 10:19 AM (12 years ago)

Custom URL plugin no internet connection

Hi all, I'm using the custom url plugin and I was wondering if there was a way to display a popup message when a device (android or iPhone) is not connected to the internet. The popup message should simply inform the user that this screen is only accessible with an internet connection. Thanks
 
Outbreak
buzztouch Evangelist
Profile
Posts: 452
Reg: May 30, 2011
Colorado
14,620
like
02/13/13 10:40 AM (12 years ago)
You could make your background say something like "This page uses an internet connection. If you still see this page, confirm your phone can receive data"....or something like that. Then if the screen loads it will cover the background. -Shane
 
Rotsos
Apple Fan
Profile
Posts: 33
Reg: Jan 30, 2013
Limassol
3,430
like
02/13/13 10:53 AM (12 years ago)
Thanks Shane for the suggestion. I just checked in an android device and if the internet connection is off I get a page that says the following. "Web page not available. The web page at htt://....... might be temporarily down or...." and so on
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
02/13/13 12:58 PM (12 years ago)
The ios version already has one, it says there was a problem downloading .... please check internet connection. If you want to add your own add these 2 methods to the .m - (BOOL) connectedToNetwork { Reachability *r = [Reachability reachabilityWithHostName:@"www.facebook.com"]; NetworkStatus internetStatus = [r currentReachabilityStatus]; BOOL internet; if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN)) { internet = NO; UIAlertView* noWifi = [[UIAlertView alloc] initWithTitle:@"Unable to load web page" message:@"This screen requires an internet connection." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [noWifi show]; [noWifi release]; //[self navLeftTap]; } else { internet = YES; } return internet; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // the user clicked one of the OK/Cancel buttons NSLog(@"clicking"); if (buttonIndex == 0) { [self navLeftTap]; } } then add this to the view did load under super viewdidload [self connectedToNetwork]; then search for this [self showAlert:nil:errorInfo:0]; and comment it out like this //[self showAlert:nil:errorInfo:0]; This stops the error about internet connection. Adds your own message plus when you press OK it sends you back to the previous screen.
 
Kaybee
buzztouch Evangelist
Profile
Posts: 659
Reg: Sep 22, 2012
Perth, Australi...
44,690
like
02/13/13 05:42 PM (12 years ago)
Great tip @Kittsy. Definitely going to use it.
 
MGoBlue
Apple Fan
Profile
Posts: 980
Reg: Jun 07, 2011
Gold River, CA
10,600
like
02/13/13 08:47 PM (12 years ago)
@Kittsy - great code. Thanks.
 
Rotsos
Apple Fan
Profile
Posts: 33
Reg: Jan 30, 2013
Limassol
3,430
like
02/14/13 12:08 AM (12 years ago)
Thank you @Kittsy this is exactly what I was looking for. Is there also a way to do this for android?
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
02/14/13 01:02 AM (12 years ago)
@rotsos Sorry mate iOS guru only at the moment. Try asking a few of the guys making android plugins
 
Rotsos
Apple Fan
Profile
Posts: 33
Reg: Jan 30, 2013
Limassol
3,430
like
02/14/13 03:15 AM (12 years ago)
Yes I will try that. Thanks again for the code you have provided for iOS
 
Rotsos
Apple Fan
Profile
Posts: 33
Reg: Jan 30, 2013
Limassol
3,430
like
02/15/13 07:11 AM (12 years ago)
Hi, I finally got this to work in Android by making some code modifications in the BT_screen_customURL.java. Basically before it loads the contents of the URL I check to see whether there is an internet connection first. If there is a connection then it loads as normally otherwise I show an alert. the code that needs to be modified is the following: //figure out what to load... if(dataURL.length() > 1){ String useUrl = BT_strings.mergeBTVariablesInString(dataURL); BT_debugger.showIt(activityName + ": loading URL from: " + useUrl); this.loadUrl(useUrl); } else { BT_debugger.showIt(activityName + ": No URL found? Not loading web-view!"); showAlert(getString(R.string.errorTitle), getString(R.string.errorLoadingScreen)); } All I did here was to replace "this.loadUrl(useUrl)" with the following: ConnectivityManager conMgr = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE); // ARE WE CONNECTED TO THE NET if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected()) { this.loadUrl(useUrl); } else { showAlert("Alert","To view this section you need an internet connection"); } Additionally you have to import this at the beginning of the file: import android.net.ConnectivityManager
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
02/15/13 07:16 AM (12 years ago)
@Rotso well done pal. And an even bigger well done for posting the actual solution, a few to many people on forums don't bother revisiting the post they asked the question in and posting the solution when they have found it. Happy apping
 

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.