방금 애플의 도달 가능성 코드를 구현했는데 내 응용 프로그램이 완전히 일관성이없고 임의의 방식으로 충돌하고 있습니다. 연속해서 20 개의 웹 페이지를로드 할 수 있었지만 21 일에는 충돌이있었습니다. 시도하거나, 단지 2 일 후에 충돌 할 수 있습니다. 웹 페이지로드 시도도달 가능성 충돌 응용 프로그램
Instruments/NSZombies는 이상한 것을 보여줍니다. RefCt는 20 자 (!)로 높으며, "Responsible Callers"는 몇 가지 다른 것들입니다 : [UIRuntimeConnection initWithCoder], [UINib instantiateWithOwner : options ], [NSKeyedUnarchiver _decodeArrayOfObjectsForKey :] 등 정상입니까?
아니면 마지막 책임자에게 집중해야합니까? RefCt를 0으로 가져 오는 [UIWindowController transitionViewDidComplete : fromView : toView :] 및 [UIWebView webView : didFinishLoadForFrame :] (이는 RefCt를 -1로 감소시킵니다)입니까?
어떻게 디버깅하고 해결할 수 있습니까?
#import "Reachability.h"
-(void) viewWillAppear:(BOOL)animated
{
// 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.apple.com"] retain];
[hostReachable startNotifier];
// now patiently wait for the notification
}
-(void) viewDidLoad {
url = [NSURL URLWithString: @"http://www.google.com"];
NSURLRequest *req = [NSURLRequest requestWithURL: url];
[webPageView loadRequest:req];
[super viewDidLoad];
}
-(void) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
//NSLog(@"The internet is down.");
//self.internetActive = NO; // (That's a BOOL variable)
[self displayMessageWithTitle:@"ERROR"
andMessage:@"Unable To Connect to Internet"
andOKButton:@"OK"];
[self dismissModalViewControllerAnimated:YES];
break;
}
case ReachableViaWiFi:
{
//NSLog(@"The internet is working via WIFI.");
//self.internetActive = YES; //
break;
}
case ReachableViaWWAN:
{
//NSLog(@"The internet is working via WWAN.");
// self.internetActive = YES; // (That's a BOOL variable)
break;
}
}
NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
switch (hostStatus)
{
case NotReachable:
{
// NSLog(@"A gateway to the host server is down.");
// self.hostActive = NO; // (That's a BOOL variable)
[self displayMessageWithTitle:@"ERROR"
andMessage:@"Host Not Reachable"
andOKButton:@"OK"];
[self dismissModalViewControllerAnimated:YES];
break;
}
case ReachableViaWiFi:
{
//NSLog(@"A gateway to the host server is working via WIFI.");
//self.hostActive = YES; // (That's a BOOL variable)
break;
}
case ReachableViaWWAN:
{
//NSLog(@"A gateway to the host server is working via WWAN.");
// self.hostActive = YES; // (That's a BOOL variable)
break;
}
}
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[activityIndicator startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[activityIndicator stopAnimating];
}
// Since this ViewController is presented Modally, this method removes it:
-(IBAction) dismissWebTixView:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
-(void) viewWillDisappear:(BOOL)animated {
NSLog(@"In webForTix's 'viewWillDisappear' method....");
[[NSNotificationCenter defaultCenter] removeObserver:self
name:kReachabilityChangedNotification
object:nil];
}
// Read somewhere that it might be better to put the removeObserver
// call here rather than viewWillDisappear...tried both - still get crashes....
- (void)dealloc
{
//NSLog(@"In webForTix's dealloc method....");
// [[NSNotificationCenter defaultCenter] removeObserver:self
// name:kReachabilityChangedNotification
// object:nil];
NSLog(@"In webForTix's dealloc method - removedObserver...");
[super dealloc];
}
세부 사항 사용을 알리는 것이 필요합니다. 'EXC_BAD_ACCESS'는 단지 할당 해제 된 어떤 객체가 호출되었다고 알려줍니다. 첫 번째 [NSZombies 사용] (http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode) 그런 다음 해당 객체가 할당 해제 된 이유를 살펴보십시오. – rckoenes
ok 나는 좀비를 켜고 충돌시 -1의 RefCt를 보여줍니다. "Categories"열에는 충돌을 일으키는 ViewController의 이름, 즉 Reachability를 가져온 VC와 Reachability 메서드가 호출 된 곳이 나와 있습니다. 이상한 점은 RefCt가 0으로 감소하기 전에 17로 높아진 다음 -1로 증가한다는 것입니다. 왜 그 일을하는거야? ViewController는 한 번만 호출 된 다음 웹 페이지를로드하는 동안 연결을 확인하는 일을 수행하고 실행합니다. 그것은 반복적으로 스스로를 부름니까? – sirab333
코드를 보여줘야합니다. – Eiko