Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7813517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:53:48+00:00 2026-06-02T04:53:48+00:00

I am having a hard time using Reachability in my code. I would like

  • 0

I am having a hard time using Reachability in my code. I would like to keep it very simple by initiating an observer at launch and then just receiving change notifications. In the following code, the reachabilityChanged method is never called. I’ve tried many iterations but this is the simplest version. It compiles and runs. Please help…

**** AppDelegate.h code ****

#import <UIKit/UIKit.h>

#ifdef PHONEGAP_FRAMEWORK
    #import <PhoneGap/PGViewController.h>
    #import <PhoneGap/PGURLProtocol.h>
    #import <PhoneGap/Reachability.h>
#else
    #import "PGViewController.h"
    #import "PGURLProtocol.h"
    #import "Reachability.h"

#endif

@interface AppDelegate : NSObject < UIApplicationDelegate, UIWebViewDelegate, PGCommandDelegate> {
    NSString* invokeString;
}

@property (nonatomic, copy)  NSString* invokeString;
@property (nonatomic, strong) IBOutlet UIWindow* window;
@property (nonatomic, strong) IBOutlet PGViewController* viewController;

@end

**** AppDelegate.m code snippet ****

#import "AppDelegate.h"

#import "MainViewController.h"

#ifdef PHONEGAP_FRAMEWORK
    #import <PhoneGap/PGPlugin.h>
    #import <PhoneGap/PGURLProtocol.h>
    #import <PhoneGap/Reachability.h>
#else
    #import "PGPlugin.h"
    #import "PGURLProtocol.h"
    #import "Reachability.h"

#endif

@implementation AppDelegate
@synthesize invokeString, window, viewController;

- (void) reachabilityChanged:(NSNotification *)notice
{

    NSLog(@"???????? CODE NEVER GETS HERE ??????????");

    Reachability *reach = [notice object];
    NSParameterAssert([reach isKindOfClass: [Reachability class]]);
    NetworkStatus remoteHostStatus = [reach currentReachabilityStatus];

    if(remoteHostStatus == NotReachable) {NSLog(@"**** Not Reachable ****");}
    else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"**** wifi ****"); }
    else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"**** cell ****"); }
}

- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{    

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];

    Reachability *reach = [Reachability reachabilityForInternetConnection];
    [reach startNotifier];

    NetworkStatus remoteHostStatus = [reach currentReachabilityStatus];

    NSLog(@”???? ALWAYS INITS WITH Not Reachable ????”);
    if(remoteHostStatus == NotReachable) {NSLog(@"init **** Not Reachable ****");}
    else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"int **** wifi ****"); }
    else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"init **** cell ****"); }

    // ...

}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:53:50+00:00Added an answer on June 2, 2026 at 4:53 am

    Your object Reachability is autorelease so it’s dealloc and not working anymore.

    I try your code and it’s working for me:

    AppDelegate.h code

    [...]
    @property (retain, nonatomic)  Reachability* reach;
    [...]
    

    AppDelegate.m code snippet

    [...]
    @synthesize reach;
    
    - (void) reachabilityChanged:(NSNotification *)notice
    {
    
        NSLog(@"!!!!!!!!!! CODE IS CALL NOW !!!!!!!!!!");
    
        NetworkStatus remoteHostStatus = [reach currentReachabilityStatus];
    
        if(remoteHostStatus == NotReachable) {NSLog(@"**** Not Reachable ****");}
        else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"**** wifi ****"); }
        else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"**** cell ****"); }
    }
    
    - (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
    {    
    
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
    
        self.reach = [Reachability reachabilityForInternetConnection]; //retain reach
        [reach startNotifier];
    
        NetworkStatus remoteHostStatus = [reach currentReachabilityStatus];
    
        NSLog(@"???? ALWAYS INITS WITH Not Reachable ????");
        if(remoteHostStatus == NotReachable) {NSLog(@"init **** Not Reachable ****");}
        else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"int **** wifi ****"); }
        else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"init **** cell ****"); }
    
        // ...
    
    }
    
    [...]
    -(void)dealloc{
        [reach release];
        [super dealloc];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a hard time using std::string::iterators in C++. This code compiles fine (still
I like the simplicity of Git but I'm having a hard time using it
I am having a very hard time using the foreach control flow binding in
This is my first time using ICU API, and I'm having a very hard
I am having a hard time using the $op variable when working with forms.
I'm having a hard time enabling git colored output on windows when using console2.
I'm having a hard time rendering a view in Haml,using MongoMapper for a small
I'm using the Utility Application template to build my app. Having a hard time
Using the Qt DBus library, I'm having a hard time registering an object implementing
I am (stuck) using Prototype 1.3.1 and I'm having a hard time moving from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.