Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-08-2009, 02:12 PM   #26 (permalink)
Persian Developer
 
Join Date: Mar 2009
Posts: 274
Default

i read your posts but Which one is correct? and i saw apple sample code but its very complex !!!
i need When the device is not connected to a network, show UIAlert that u must connect to internet ..
__________________
My Applications On the App Store


Momeks is offline   Reply With Quote
Old 08-09-2009, 10:49 AM   #27 (permalink)
Persian Developer
 
Join Date: Mar 2009
Posts: 274
Default

i used this code from connectivity erica sadun book :

Quote:
#import <UIKit/UIKit.h>
#import <SystemConfiguration/SystemConfiguration.h>
#include <netdb.h>

#define COOKBOOK_PURPLE_COLOR [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f]
#define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target:self action:SELECTOR] autorelease]

@interface TestBedViewController : UIViewController
@end

@implementation TestBedViewController
- (BOOL) connectedToNetwork
{
// Create zero addy
struct sockaddr_in zeroAddress;
bzero(&zeroAddress, sizeof(zeroAddress));
zeroAddress.sin_len = sizeof(zeroAddress);
zeroAddress.sin_family = AF_INET;

// Recover reachability flags
SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
SCNetworkReachabilityFlags flags;

BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachabi lity, &flags);
CFRelease(defaultRouteReachability);

if (!didRetrieveFlags)
{
printf("Error. Could not recover network reachability flags\n");
return NO;
}

BOOL isReachable = ((flags & kSCNetworkFlagsReachable) != 0);
BOOL needsConnection = ((flags & kSCNetworkFlagsConnectionRequired) != 0);
return (isReachable && !needsConnection) ? YES : NO;
}

- (void) viewDidLoad
{
self.navigationController.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR;
self.title = [self connectedToNetwork] ? @"Connected" : @"Not Connected";
}
@end

@interface TestBedAppDelegate : NSObject <UIApplicationDelegate>
@end

@implementation TestBedAppDelegate
- (void)applicationDidFinishLaunchingUIApplication *)application {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[TestBedViewController alloc] init]];
[window addSubview:nav.view];
[window makeKeyAndVisible];
}
@end
what can i replace this line with UIAlertView ?

self.title = [self connectedToNetwork] ? @"Connected" : @"Not Connected";
__________________
My Applications On the App Store


Momeks is offline   Reply With Quote
Old 08-09-2009, 11:09 AM   #28 (permalink)
Persian Developer
 
Join Date: Mar 2009
Posts: 274
Default

i solved my problem replace this :



- (void) viewDidLoad {
if (![self connectedToNetwork]) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Network Connection Error"
message:@"You need to be connected to the internet to use this feature."
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
__________________
My Applications On the App Store


Momeks is offline   Reply With Quote
Old 08-27-2009, 06:08 PM   #29 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 11
Default

Note that the Reachability example was rewritten so the above will not work via simple copy/paste...

The new code in your app would look like this:

Quote:
Reachability *r = [Reachability reachabilityWithHostName:@"www.maxqdata.com"];

NetworkStatus internetStatus = [r currentReachabilityStatus];

if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
{
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"You require an internet connection via WiFi or cellular network for location finding to work." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
}

Last edited by sleepless; 08-27-2009 at 06:13 PM.
sleepless is offline   Reply With Quote
Old 10-06-2009, 11:37 AM   #30 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 120
Default Rhawkey where is the information located at that...

Quote:
Originally Posted by rhawkey View Post
This case is specifically mentioned very early on in the iPhone user interface guidelines. Do what iTunes does , the blank view with the message and big wifi image. If you haven't read the guidelines you should as my experience has been very not fun being rejected and reset in the long approval queues for silly things like using a button image incorrrectly.
Rhawkey where is the information located at that tells a person exactly what things will be rejected and what is proper? I just got a job as an Iphone developer been doing it for almost three weeks now.
softwarespecial is offline   Reply With Quote
Old 10-06-2009, 12:36 PM   #31 (permalink)
Registered Member
 
Join Date: May 2009
Location: Canada
Posts: 23
Default

Quote:
Originally Posted by softwarespecial View Post
Rhawkey where is the information located at that tells a person exactly what things will be rejected and what is proper? I just got a job as an Iphone developer been doing it for almost three weeks now.
http://developer.apple.com/iphone/li.../MobileHIG.pdf

That's the human interface guidelines, which they will reject your app if you violate (depending on who you get reviewing your app, sometimes things slip through, usually they don't). That only covers the look and feel of your app, not all the other hundreds of things Apple is known to reject apps for. You should google app rejection and read all the articles about that to learn the most common ones (not functioning properly when the network isn't available, nudity, certain types of violent content, etc...).
rhawkey is offline   Reply With Quote
Old 10-06-2009, 12:53 PM   #32 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 120
Default Thanks for the help

Thanks
softwarespecial is offline   Reply With Quote
Old 05-03-2010, 05:46 AM   #33 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 2
Default

I have a little question about how to check for false positive.

When i e.g have my iphone connected to a wifi hotspot which demands that i need to type in a username and password before i can connect to the internet, I still get the flags that says that i`m connected to wifi.

What I am asking is this, when a phone is connected to a router but the router aint connected to the internet, i need the program to then say that i`m not connected to the internet. How can you archieve that with the use of the reachability code?
Peewee is offline   Reply With Quote
Old 05-03-2010, 11:50 AM   #34 (permalink)
Registered Member
 
Join Date: May 2009
Location: Canada
Posts: 23
Default

Quote:
Originally Posted by Peewee View Post
I have a little question about how to check for false positive.

When i e.g have my iphone connected to a wifi hotspot which demands that i need to type in a username and password before i can connect to the internet, I still get the flags that says that i`m connected to wifi.

What I am asking is this, when a phone is connected to a router but the router aint connected to the internet, i need the program to then say that i`m not connected to the internet. How can you archieve that with the use of the reachability code?
That's the host part of the reachability class. You can check not only whether the device is connected to a network but also whether a host is reachable. So if you check whatever your end target is that you're trying to connect to then you know the router is online. The remoteHostStatus method is what you're looking for.

By the way be careful where you put these tests. I've had some apps crash from timeouts on launch by having them in the startup code for my app. In the end I moved all of my reachability testing to a thread which sets a flag that I later poll from the main thread. Not only the network device connection test but also the host test can take a really long time and trigger the iPhone OS watchdog to kill your app if it's on the main thread.
rhawkey is offline   Reply With Quote
Old 05-04-2010, 06:41 AM   #35 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 2
Default

Quote:
Originally Posted by rhawkey View Post
That's the host part of the reachability class. You can check not only whether the device is connected to a network but also whether a host is reachable. So if you check whatever your end target is that you're trying to connect to then you know the router is online. The remoteHostStatus method is what you're looking for.

By the way be careful where you put these tests. I've had some apps crash from timeouts on launch by having them in the startup code for my app. In the end I moved all of my reachability testing to a thread which sets a flag that I later poll from the main thread. Not only the network device connection test but also the host test can take a really long time and trigger the iPhone OS watchdog to kill your app if it's on the main thread.
Hi and thanks a lot for your awnser. I can`t seem to find the remoteHostStatus that you are talking about.

I am using the method
Code:
+ (Reachability*) reachabilityWithHostName: (NSString*) hostName;
Aint that the right one?

Right now i am using the following code to test several differents scenarios.

Code:
	hostReach = [[Reachability reachabilityWithHostName: @"www.google.com"] retain];
	[hostReach startNotifer];
	[self updateInterfaceWithReachability: hostReach];
	
	internetReach = [[Reachability reachabilityForInternetConnection] retain];
	[internetReach startNotifer];
	[self updateInterfaceWithReachability: internetReach];
	
    wifiReach = [[Reachability reachabilityForLocalWiFi] retain];
	[wifiReach startNotifer];
	[self updateInterfaceWithReachability: wifiReach];
I have 3 different objects of the reachability class where one is initialised with the host example, another with internetReach and the last one with localwifi. This code is taken right from Apples example class that follows with the Reachability code from their homepage. When i run apples reachability code all seems to be running fine. With that i meen that when i am connected to to a wifi that can reach out on the net, the application (reachability) says that all three object can reach the internet ture wifi, while if I connect to a wifi which is not connected to the internet i get not able to connect from two of the reachability objects (reachabilityForInternetConnection and reachabilityWithHostName) while reachabilityForLocalWiFi still give me back wifi aviliablewhich are correct.

Thats why i can`t see why it fails now when i just move the code from apples example into my project. I thought i was using the code correctly, but in my application i get the go ahead on all three object when i am connected to a wifi which aint connected to the internet. Only the local wifi should give me that. Any help on this subject would be greatly apprishiated (You was talking about the last versions of apples reachability code right?

And thanks a lot for the heads up about the watchdog. I have read something about this in other threads about the subject asweel, but right now i actually have it in the startup of the program So guess i have to try fix that.

Is there any chance that you might post some of your code or show me a good example of how you run in it in another thread? And how you get the code to properly check if it can reach the host or not

Thanks for your help so far

Last edited by Peewee; 05-04-2010 at 07:02 AM. Reason: More info
Peewee is offline   Reply With Quote
Old 05-04-2010, 01:19 PM   #36 (permalink)
Registered Member
 
Join Date: May 2009
Location: Canada
Posts: 23
Default

Yeah that looks good.

Unfortunately I can't post the code I wrote for doing it asynchronously as it is owned by the client I wrote it for, not me.

If you haven't already you should read the thread document in the help resources and learn about NSOperation and NSOperationQueue, which make doing jobs like this on threads very clean and simple.
rhawkey is offline   Reply With Quote
Old 08-12-2010, 02:15 PM   #37 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 60
Default

this worked for me using the latest Reachability code (as of August 12,2010)

Quote:
// check for network status
Reachability *hostReach = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
NetworkStatus netStatus = [hostReach currentReachabilityStatus];

if(netStatus == NotReachable) {
// show network not found alert here
}
btw, don't do this in your AppDelegate class. It will block your app coming up. Better to do this in your some other view controller or see the Reachability code to implement it as asynchronous call with notifier.
__________________
My Apps in AppStore
ZubiZubi is offline   Reply With Quote
Old 08-27-2010, 08:06 AM   #38 (permalink)
Eigo
 
Join Date: Apr 2010
Posts: 12
Default

The Reachability sample code has been updated to verison2.2 which works on iOS4.0 only, this is okay but iPad only has iOS3.2 at the moment so we cannot use this code on iPad apps, previous versions worked on iOS3.2.

Anyone got a link to version2.1 of Reachability?
Eigo is offline   Reply With Quote
Old 08-27-2010, 09:20 AM   #39 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by Eigo View Post
The Reachability sample code has been updated to verison2.2 which works on iOS4.0 only, this is okay but iPad only has iOS3.2 at the moment so we cannot use this code on iPad apps, previous versions worked on iOS3.2.

Anyone got a link to version2.1 of Reachability?
That's not true! I use 2.2 in an iPad-only project without problems.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 08-29-2010, 08:16 PM   #40 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 16
Default

Quote:
Originally Posted by Oliver Drobnik View Post
That's not true! I use 2.2 in an iPad-only project without problems.
Do you know if that is true for OS 3.0+ or just for 3.2?
ufbobbo is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 356
22 members and 334 guests
ADY, Dani77, Duncan C, e2applets, Grinarn, HemiMG, Herbie, JasonR, keeshux, linkmx, macquitzon216, mer10, Monstertaco, prchn4christ, Promo Dispenser, Robiwan, sebasx, sly24, Touchmint, twerner, zulfishah
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,881
Threads: 89,228
Posts: 380,760
Top Poster: BrianSlick (7,129)
Welcome to our newest member, macquitzon216
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:37 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0