Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
is there a simple piece of code testing if the internet is available on the iPhone - i know the reachability example app but that seems to be a great overhead. So i only like a network test (CFNetwork ?) who can check this - any help available?
It seems there is a bit of an issue with the above code and it may need to be modified depending upon your intended use. I put this code into my app (original code provided by Apple; thank you Apple) and it only worked when the iPhone was on a WiFi connection. I did some research and testing to come up with a solution. There are a set of flags that can be used to determine connectivity (iPhone Dev Center). Not being entirely sure which to use, I set up a tester that would show me which flags are active when I am using different connection methods. This is something that I would recommend anyone to try so that you can get a better understanding of how it works, however this is the change I made that seemed to fix the issue:
If someone knows a better way or if im completely wrong here, please let me know. The problem I am trying to research now is that once the iPhone has left the WiFi connection and gone on to the 3G or Edge networks, it wont go back onto the WiFi again even if I am in range of the signal. I have to exit my app and either wait or reinitialize it in the settings. Does anyone know a way around this?
What (I think) its doing is after it tests for reachability, it requests data from a www site using NSURLConnection, which makes the iPhone search for connections. Sorry for my non-technical explanations :)
EDIT: I changed the cache policy to not pull from the local cache so that it looks for the page every time. In my code, I also am not using apple.com as the request URL. I put up a simple html page on my server with the word 'true' in it and I am requesting that page for the connection testing. Keeping the request small might help the load time, even if you are doing nothing with the requested data. Even a 404 returns something.
This is very very good thread ,,atmost usefulllll.. but unable to understand , what does the zeroaddress contains..Any link on web would be help ful for understanding this.. Thank u all.
This is very very good thread ,,atmost usefulllll.. but unable to understand , what does the zeroaddress contains..Any link on web would be help ful for understanding this.. Thank u all.
The zero address is simply 0.0.0.0 - I in fact, chose to use apple.com to check for connectivity ...[self hostAvailable:@"www.apple.com"]....
The Reachability sample code is what you should be looking at here. Although the class it uses is almost 1000 lines long, it shows you how it all works. I'm about to start picking through it all for what I need:p
I like the idea of loading a small string from the web. I tested it on the simulator and the following code works fine if my internet is connected or not connected. I gave it a 2 second timeout...
EDIT: Tested it on the device as part of a much bigger app. Works as expected in flight mode / normal connection. If you want to increase the timeout perhaps it might be worth it, but it's working fine for me!
is there a simple piece of code testing if the internet is available on the iPhone - i know the reachability example app but that seems to be a great overhead. So i only like a network test (CFNetwork ?) who can check this - any help available?
Cheers :-) Ralf
Two methods I tried. Reachability is still the best for me. It detect even changes from WifI to 3G to EDGE, etc...
Easier to use method is the UIWebView protocol itself. Hope the code below helps.
#pragma mark UIWebView delegate methods
- (void)webViewDidStartLoad:(UIWebView *)webView { // starting the load, show the activity indicator in the status bar [myActivityIndicatorView startAnimating]; }
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { int myErrorCode;
[myActivityIndicatorView stopAnimating];
myErrorCode = [error code]; // myErrorCode = -999 if user cancel action, not network problem if (ckErrorCode != -999) { // Your error handling code here NSLog(@"UIWebView Load Failed-Error"); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error!" message:@"Unable to connect to the website." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; [alert show]; } }
Hi! I read all the posts here and there is currently no working solution for setting timeout. Fe.: wait(20000); writes "Passing argument 1 of wait makes pointer from integer without a cast"...
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeYou could use a hidden UIWebView and load a website to it. Then use methods from the UIWebView.h to detect, whether loading was successful or not.
Friendlydeveloper - Coding Blog
Codingsessions - Live iOS Training
iPhone Apps:
<a hr
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomehmm that sounds a bit crazy :-)
Here is the code (tested and working fine):
Ciao
Ralf
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeWhat if your iPhone connects to a wireless router, and that router is not connected to the internet? Will your app fail gracefully?
-peace
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome#import
#include
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomethe code above doesn't detect cellular network. any idea on how to do that?
Ashar
www.tkxel.com
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThere are a set of flags that can be used to determine connectivity (iPhone Dev Center). Not being entirely sure which to use, I set up a tester that would show me which flags are active when I am using different connection methods. This is something that I would recommend anyone to try so that you can get a better understanding of how it works, however this is the change I made that seemed to fix the issue:
If someone knows a better way or if im completely wrong here, please let me know.
The problem I am trying to research now is that once the iPhone has left the WiFi connection and gone on to the 3G or Edge networks, it wont go back onto the WiFi again even if I am in range of the signal. I have to exit my app and either wait or reinitialize it in the settings. Does anyone know a way around this?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeWhat (I think) its doing is after it tests for reachability, it requests data from a www site using NSURLConnection, which makes the iPhone search for connections. Sorry for my non-technical explanations :)
EDIT: I changed the cache policy to not pull from the local cache so that it looks for the page every time. In my code, I also am not using apple.com as the request URL. I put up a simple html page on my server with the word 'true' in it and I am requesting that page for the connection testing. Keeping the request small might help the load time, even if you are doing nothing with the requested data. Even a 404 returns something.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThis is very very good thread ,,atmost usefulllll..
but unable to understand , what does the zeroaddress contains..Any link on web would be help ful for understanding this..
Thank u all.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThis function will return NO if it cannot reach the file. Otherwise, it will return YES. I tried it in flight mode and in 3G mode. It works.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI tested it this way but my application will just wait and wait and wait and wait... I need to set a timeout. Can u tell me how?
EDIT: What datatype is this nonWifi?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- (BOOL) connectedToNetwork {
return ([NSString stringWithContentsOfURL:[NSURL URLWithString:@\"http://www.apple.com/\"]]!=NULL)?YES:NO;
if (YES) {
}
if (NO) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@\"no internet connection\"
delegate:self cancelButtonTitle:@\"OK\" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
Search GetFit! on the App Store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeiTasks - Task Manager/Todo List
<a href="http://steaps.techaos.com/" targe
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeEDIT: Tested it on the device as part of a much bigger app. Works as expected in flight mode / normal connection. If you want to increase the timeout perhaps it might be worth it, but it's working fine for me!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThanks for the code ziophase.
10 Detailed Steps to Submit Apps To AppStore
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeTwo methods I tried. Reachability is still the best for me. It detect even changes from WifI to 3G to EDGE, etc...
Easier to use method is the UIWebView protocol itself. Hope the code below helps.
#pragma mark UIWebView delegate methods
- (void)webViewDidStartLoad:(UIWebView *)webView
{
// starting the load, show the activity indicator in the status bar
[myActivityIndicatorView startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[myActivityIndicatorView stopAnimating];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
int myErrorCode;
[myActivityIndicatorView stopAnimating];
myErrorCode = [error code]; // myErrorCode = -999 if user cancel action, not network problem
if (ckErrorCode != -999)
{
// Your error handling code here
NSLog(@"UIWebView Load Failed-Error");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error!" message:@"Unable to connect to the website." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
}
// #pragma mark UIWebView delegate methods
iPhone SDK Fanatic!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome10 Detailed Steps to Submit Apps To AppStore
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThere's a much better way to do it!
Download the apple sample code reachability.
Then follow the steps listed in post 29 here:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/19546-no-wifi-connection-best-practice-2.html#post118631
Cheerio
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI read all the posts here and there is currently no working solution for setting timeout. Fe.: wait(20000); writes "Passing argument 1 of wait makes pointer from integer without a cast"...
Is there any way how to create timeout for:
- (BOOL) connectedToNetwork
{
return ([NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com"] encoding:NSASCIIStringEncoding error:nil]!=NULL)?YES:NO;
}
?
Thanks a lot.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome