2012-04-17 11 views
6

मुझे अपने कोड में पहुंच क्षमता का उपयोग करने में कठिनाई हो रही है। मैं लॉन्च पर एक पर्यवेक्षक शुरू करके और फिर केवल परिवर्तन अधिसूचनाएं प्राप्त करके इसे बहुत सरल रखना चाहता हूं। निम्नलिखित कोड में, पहुंच योग्यताबद्ध विधि कभी नहीं कहा जाता है। मैंने कई पुनरावृत्तियों की कोशिश की है लेकिन यह सबसे सरल संस्करण है। यह संकलित और चलाता है। कृपया मदद ...पहुंच योग्यता अधिसूचना कभी नहीं बुलाया

** * * AppDelegate.h कोड * ** *

#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 कोड स्निपेट * ** *

#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 
+0

निश्चित रूप से शीर्षक और/या टैग को इस प्रश्न को पहचानने में आसान बनाने के लिए अपडेट किया जा सकता है ... –

+0

बस संपादित - आशा है कि शीर्षक और टैग अधिक वर्णनात्मक हैं। –

उत्तर

26

आपका वस्तु गम्यता autorelease तो यह dealloc है और अब और काम नहीं कर रहा।

मैं अपने कोड की कोशिश और यह मेरे लिए काम कर रहा है:

AppDelegate.h कोड

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

AppDelegate.m कोड स्निपेट

[...] 
@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

मुझे लगता है कि यह है! मैंने हवाई जहाज मोड को चालू करके अपने संशोधनों का प्रयास किया और मुझे उचित लॉग संदेश दिखाई दिए। आपका बहुत - बहुत धन्यवाद! –

+0

@ सराह मोरलैंड आपका स्वागत है। जैसा कि आप एक नए उपयोगकर्ता हैं, मैं आपको अपने उत्तर के लिए वोट देने के लिए याद दिलाने की स्वतंत्रता लेता हूं यदि आप इसे पसंद करते हैं और/या जवाब को स्वीकार करते हैं तो यह आपकी समस्या का समाधान करता है। बटन मेरे उत्तर –

+0

के ऊपरी बाईं ओर है धन्यवाद, मैंने स्वीकृति उत्तर की जांच की लेकिन वोट देने में असमर्थ हूं क्योंकि मेरे पास 15 प्रतिष्ठा नहीं है। अगर मैं कर सकता तो मैं कर देता। यह एक अच्छा जवाब है। –

संबंधित मुद्दे