i have been researching how to do this, and while i believe my code is
correct, i always receive the alert stating the internet connection is
unavailable.  what am i doing wrong?

-=-=-=-=-
- (BOOL)internetConnection
        {
        //INTERNET CONNECTION TESTING
        //Add the SystemConfiguration framework
        //#import <SystemConfiguration/SCNetworkReachability.h>
        //#include <netinet/in.h>
        
        //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(defaultRouteReachability, &flags);
        CFRelease(defaultRouteReachability);

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

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

- (IBAction)gotoAppStore
        {
        if (internetConnection == YES)
                [[UIApplication sharedApplication] openURL:[NSURL
URLWithString:@"http://www.google.com";]];
                else
                {
                UIAlertView *alert = [[UIAlertView alloc]       
initWithTitle:nil
                                                                        
message:NSLocalizedString(SMConstNoInternetConnectionAlertMessage,
nil)
                                                                        
delegate:self
                                                                        
cancelButtonTitle:@"OK"
                                                                        
otherButtonTitles:nil];
                [alert show];
                [alert release];
                }
        }
-=-=-=-=-
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to