我有一个View Controller,可以从我的facebook帮助器中实现一些委托方法。当点击一些图标(如图标)时,我的应用程序切换到Facebook移动网络登录。之后,它切换回我的应用程序,但是,该应用程序需要更多的写入权限,因此Facebook移动网络(safari)再次切换。我按OK然后完成操作。
但是,我的View Controller中的委托方法未被调用。我调试并且可以看到当时facebook动作发生,变量“delegate”为零。
我的视图控制器有一些特别之处每次从背景返回时,它会呈现另一个视图控制器(用于赞助商屏幕)。显示持续时间约为3秒,然后赞助商屏幕消失。
如何调用委托方法?
在我看来控制器
[FacebookHelper sharedInstance].fbDelegate = self;
[[FacebookHelper sharedInstance] likeCommentFacebook:!isLike withCommentID:message.messageID];
在我的facebook帮手:
` - (void)likeCommentFacebook:(BOOL)isLike withCommentID:(NSString *)commentID
{
//- 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];
}
}
}];
}
}
}`
和回调方法
if (self.fbDelegate && [self.fbDelegate respondsToSelector:@selector(likeCommentDidSuccess:)]) {
[self.fbDelegate performSelector:@selector(likeCommentDidSuccess:) withObject:dictionary];
}
答案 0 :(得分:0)
是否已将delegate
设置为self
中的ViewController
,并在yourViewController
的.h文件中提及/实施了该代理,如下所示。
<强> yourViewController.h 强>
@interface yourViewController : UIViewController<yourDelegate>
<强> yourViewController.m 强>
[yourComponent setYourDelegate:self];