2012-07-02 17 views
1

我試圖從我的應用程序上傳照片到Facebook,並且一切順利,當我上傳並等待它完成時,但是當我按上傳然後回到之前的view,上傳完成後我得到一個錯誤URL響應中的指針不佳

Thread 1:EXC_BAD_ACCESS(code=2, address=0x9) 

在代碼:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 
_responseText = [[NSMutableData alloc] init]; 

NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; 
if ([_delegate respondsToSelector: 
    @selector(request:didReceiveResponse:)]) { 
    [_delegate request:self didReceiveResponse:httpResponse]; 
} 
} 

它打破在if。我不知道我會如何去解決這個問題。

謝謝

編輯: 之前,我回到以前的觀點這就是所謂的:

-(IBAction)shareToFacefook{ 
     [[self appDelegate] facebooking]; // checke that the user is loged in 
     NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
            labeledImage, @"source", 
            [[MyStrings myLocalStrings] getBackLocalstring:FB_IMG_POST_TITLE],@"message", 
            nil]; 

    [[[self appDelegate] getFacebookVar] requestWithGraphPath:[NSString stringWithFormat: @"/me/photos?access_token=%@", self.appDelegate.getFacebookVar.accessToken] andParams:params andHttpMethod:@"POST" andDelegate:self]; 
} 

回答

0

似乎是一個內存管理問題。 EXC_BAD_ACCESS通常表示正在訪問的內存地址不再有效。

當您收到它時,是否使用retain遞增_delegate的引用計數?如果沒有,那麼它可能已被垃圾收集。您應該在收到代理時使用retain或創建代表的copy

+0

我該怎麼做?這個方法是'nsurl'委託的一部分。這是所有在後臺調用...我做的是[[[自[appDelegate] getFacebookVar] requestWithGraphPath:[NSString stringWithFormat:@「/ me/photos?access_token =%@」,self.appDelegate.getFacebookVar.accessToken] andParams:params andHttpMethod:@「POST」andDelegate:self];'。對不起,它太混亂了。 –

+1

您應該將該代碼添加到問題中 - 註釋中的格式使其難以閱讀。 :/ – jimbojw

0

你可以試試這個: 1.檢查Facebook.m 2.find了 「的dealloc」 3.you'll看到下面的代碼:

for (FBRequest* _request in _requests) { 
     [_request removeObserver:self forKeyPath:requestFinishedKeyPath]; 
    } 

它替換到

for (FBRequest* _request in _requests) { 
     _request.delegate = nil; 
     [_request removeObserver:self forKeyPath:requestFinishedKeyPath]; 
    }