2013-09-06 2 views
0

내 페이스 북 도우미에서 일부 대리자 메서드를 구현하는보기 컨트롤러가 있습니다. 아이콘과 같은 일부 아이콘 (아이콘)을 두 드릴 때 내 앱이 Facebook 웹 사이트로 이동하여 로그인합니다. 그 후, 그것은 다시 내 애플 리케이션을 전환하지만, 응용 프로그램은 페이 스북 모바일 웹 (사파리) 그래서 다시 한번 쓰는 더 많은 권한이 필요합니다. 확인을 누르면 작업이 완료됩니다. 그러나 내 View Controller의 대리자 메서드는 호출되지 않습니다. 내가 디버그하고 그 시간에 페이 스북 액션이 일어나는 것을 볼 수있다. 변수 "delegate"는 nil이다. 내보기 컨트롤러에는 특별한 것이 있습니다. 백그라운드에서 되돌아 갈 때마다 다른보기 컨트롤러 (스폰서 화면 용)가 표시됩니다. 표시 시간은 약 3 초가 소요되며 스폰서 화면이 사라집니다.
어떻게 위임 메서드를 호출 할 수 있습니까? (BOOL)인가 봐요 withCommentID이 : (있는 NSString *)는 {숨겨진 경우 대리자 메서드가 호출되지 않습니다.

//- check if we are already processed by the loginCallback 
if (_loginCallbackInvocation == nil) { 
    //- create NSInvocation reference to this method 
    NSInvocation * nsi = [WKTools invocationWithTarget:self selector:_cmd retainArguments:TRUE argumentAddresses:&isLike, &commentID]; 
    //- ensure user has been properly identified and process with authentication if required 
    [self processLogin:nsi]; 
} 

//- check if user session is valid 
if ([[FBSession activeSession] isOpen]) { 
    if (![self hasPermission:kPublishStream]) { 
     NSArray *permissions = [NSArray arrayWithObjects: kPublishStream,nil]; 
     dispatch_async(dispatch_get_current_queue(), ^{ 
      [FBSession.activeSession requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession *session, NSError *error) { 
       NSString *requestUrl = [NSString stringWithFormat:@"%@%@", commentID,FB_REQUEST_LIKE]; 
       NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"", MESSAGE_KEY, nil]; 
       //- send request 
       if (isLike == YES) { 
        [self requestGraphAPI:requestUrl parameter:params httpMethod:POST_METHOD]; 
       } else { 
        [self requestGraphAPI:requestUrl parameter:params httpMethod:DELETE_METHOD]; 
       } 
      }]; 
     }); 
    } else { 
     NSString *requestUrl = [NSString stringWithFormat:@"%@%@", commentID,FB_REQUEST_LIKE]; 
     NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"", MESSAGE_KEY, nil]; 
     //- send request 
     if (isLike == YES) { 
      [self requestGraphAPI:requestUrl parameter:params httpMethod:POST_METHOD]; 
     } else { 
      [self requestGraphAPI:requestUrl parameter:params httpMethod:DELETE_METHOD]; 
     } 
    } 
} else { 
    if ([self isSessionCachedAndLoaded]) { 
     [FBSession.activeSession openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error) { 
      if (![self hasPermission:kPublishStream]) { 
       [[NSUserDefaults standardUserDefaults] synchronize]; 
       NSArray *permissions = [NSArray arrayWithObjects: kPublishStream,nil]; 
       dispatch_async(dispatch_get_current_queue(), ^{ 
        [FBSession.activeSession requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession *session, NSError *error) { 
         NSString *requestUrl = [NSString stringWithFormat:@"%@%@", commentID,FB_REQUEST_LIKE]; 
         NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"", MESSAGE_KEY, nil]; 
         DEBUGLog(@"like comment: %@",requestUrl); 

         //- send request 
         if (isLike == YES) { 
          [self requestGraphAPI:requestUrl parameter:params httpMethod:POST_METHOD]; 
         } else { 
          [self requestGraphAPI:requestUrl parameter:params httpMethod:DELETE_METHOD]; 
         } 
        }]; 
       }); 
      } else { 
       NSString *requestUrl = [NSString stringWithFormat:@"%@%@", commentID,FB_REQUEST_LIKE]; 
       NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"", MESSAGE_KEY, nil]; 
       //- send request 
       if (isLike == YES) { 
        [self requestGraphAPI:requestUrl parameter:params httpMethod:POST_METHOD]; 
       } else { 
        [self requestGraphAPI:requestUrl parameter:params httpMethod:DELETE_METHOD]; 
       } 
      } 
     }]; 
    } 
} 

}`

을 commentID - (무효) likeCommentFacebook가 가
`: 내 페이스 북 도우미에서
[FacebookHelper sharedInstance].fbDelegate = self; [[FacebookHelper sharedInstance] likeCommentFacebook:!isLike withCommentID:message.messageID];
내보기 컨트롤러에서

및 콜백 방법


if (self.fbDelegate && [self.fbDelegate respondsToSelector:@selector(likeCommentDidSuccess:)]) { [self.fbDelegate performSelector:@selector(likeCommentDidSuccess:) withObject:dictionary]; }

+0

우리는 코드를 보지 않고 도울 수 없어요. – trojanfoe

+0

흐름이 많은 메소드와 블록을 통과하기 때문에 코드를 게시하기가 어렵습니다. 내가 발견 한 또 하나의 점은 NSNotificationCenter를 사용하여 내 ViewController의 메서드로 알림을 후크하면 메서드는 반환 된 신호를받을 수 있다는 것입니다. – lenhhoxung

+0

우리가 무엇을 할 수 있는지 잘 모르겠습니다. 델리게이트가 '무 (無)'로가는 이유는 순수한 추측입니다. – trojanfoe

답변

0

ViewController에서 delegateself으로 설정했으며 위의 yourViewController의 .h 파일에서 위임을 언급/구현했습니다.

yourViewController.h

@interface yourViewController : UIViewController<yourDelegate> 

yourViewController.m는

[yourComponent setYourDelegate:self]; 
+0

, 물론 이것이 내 서비스 도우미를 위해 설정 한 첫 번째 것입니다. – lenhhoxung

+0

아, 결국 원인을 발견했습니다. viewWillDisappear 메서드에서 대기중인 요청의 충돌을 피하기 위해 delegate = nil을 설정했습니다. 모달 뷰 컨트롤러가 항상 내 View Controller 위에 나타나기 때문에 메서드는 delegate nil을 호출하도록 호출됩니다. – lenhhoxung

+0

@lenhhoxung : 좋습니다 ... 좋습니다 ... –

관련 문제