崩潰時我有一個名爲-(void) loadUrl:(NSString *) SearchStr
。在方法,我將值分配到全局的NSString幫我 - 應用程序打印全局的NSString變量
變量。然後我使用[self checkReach]
調用Apple的網絡可達性類方法。
在該函數中,我可以打印該nsstring變量。並再次調用metod被調用的
- (void) checkNetworkStatus:(NSNotification *)notice;
。
在那個函數中,我無法打印nnstring varibale。 這使我的應用程序崩潰。
我不知道,爲什麼這個全局變量在- (void) checkNetworkStatus:(NSNotification *)notice;
方法中不可訪問?
任何幫助將不勝感激!
謝謝你的時間。
找到下面的代碼; -
#in the header file.
@property(nonatomic, retain) NSString* myEscapedUrlString;
#in the m file
@synthesize myEscapedUrlString;
-(void) loadUrl:(NSString *) SearchStr
{
myEscapedUrlString = SearchStr;
NSLog(@"%@ ###########",myEscapedUrlString);
[self checkReach];
}
-(void)checkReach
//----------------
{
NSLog(@"%@ nnnnnnnnnnnnnnnnn",myEscapedUrlString);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(load_View) name: UIApplicationDidBecomeActiveNotification object:nil];
// check for internet connection
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
internetReachable = [[Reachability reachabilityForInternetConnection] retain];
[internetReachable startNotifier];
// check if a pathway to a random host exists
hostReachable = [[Reachability reachabilityWithHostName: @"www.testn.com"] retain];
[hostReachable startNotifier];
}
- (void) checkNetworkStatus:(NSNotification *)notice;
//---------------------------------------------------
{
NSLog(@"%@ nnnnnnnnnnnnnnnnn",myEscapedUrlString);
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:kReachabilityChangedNotification object:nil];
if (internetStatus == NotReachable)
{
NSLog(@"The internet is down.");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Network Status"
message:@"Internet connection is not availbale. Check your connections." delegate:self
cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
else if (hostStatus == NotReachable)
{
NSLog(@"A gateway to the host server is down.");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Network Status"
message:@"Cannot connect to Aghaven server. Please try again later." delegate:self
cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
}
查看日誌,並請告訴我們它崩潰的原因 – 2011-06-15 05:32:13