presentRequestsDialogModallyWithSession不起作用,但给人好的结果 [英] presentRequestsDialogModallyWithSession does not work, but gives good result
问题描述
当我用webdialog的friendrequest,一切都进展正常,但没有要求或任何制成。
在code:
的NSMutableDictionary * PARAMS = [的NSMutableDictionary dictionaryWithObjectsAndKeys:
facebookFriend.id,@到
零];
[FBWebDialogs presentRequestsDialogModallyWithSession:FBSession.activeSession
消息:NSLocalizedString(@FB_FRIEND_INVITE_MESSAGE,@Facebook好友邀请消息)
标题:NSLocalizedString(@FB_FRIEND_INVITE_TITLE,@Facebook好友邀请题)
参数:PARAMS
处理:^(FBWebDialogResult结果,NSURL * resultURL,NSError *错误){
}];
这是结果我得到:
<?pre> fbconnect://成功申请= XXXXXXXXXXXX和放大器;到%5B0%5D = XXXXXXXX
我
如何调试什么错误?
先谢谢了。
范尼
对于 SDK 3.2或以上:我们有一个设施使用 FBWebDialogs 类,这将有助于我们展现与好友列表,并沿弹出选择一个或多个列表发送邀请。
让你一步一步:
1)下载并安装<一href=\"http://stackoverflow.com/questions/14157784/can-we-invite-people-to-use-our-app-or-send-friend-request-from-the-app-via-face/16605625#16605625\">SDK 3.2 或以上。
2)首先设置你按照这个一个在Facebook上的应用> URL。
3)然后使用附带的code。
样code:(它生成邀请好友请求)
- (无效)inviteFriends
{
如果([FBSession activeSession] isOpen会])
{
*的NSMutableDictionary PARAMS = [的NSMutableDictionary dictionaryWithObjectsAndKeys:无];
[FBWebDialogs presentRequestsDialogModallyWithSession:无
消息:自getInviteFriendMessage]
标题:无
参数:PARAMS
处理:^(FBWebDialogResult结果,NSURL * resultURL,NSError *误差)
{
如果(错误)
{
[个体经营requestFailedWithError:错误]
}
其他
{
如果(结果== FBWebDialogResultDialogNotCompleted)
{
[个体经营requestFailedWithError:无];
}
否则,如果([resultURL说明】有preFIX:@fbconnect://成功申请=])
{
// Facebook的返回FBWebDialogResultDialogCompleted甚至用户
// presses取消按钮,所以我们区分它的基础上,
// URL值,因为它会返回请求当我们真正
//完成对话
[个体经营requestSucceeded]
}
其他
{
//用户取消对话框
[个体经营requestFailedWithError:无];
}
}
}
]; }
其他
{
/ *
*打开与发布许可的新会话
* /
[FBSession openActiveSessionWithPublishPermissions:[NSArray的arrayWithObject:@publish_stream]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *会话,FBSessionState状态,NSError *误差)
{
如果(误差放大器和;!&安培;状态== FBSessionStateOpen)
{
*的NSMutableDictionary PARAMS = [的NSMutableDictionary dictionaryWithObjectsAndKeys:无];
[FBWebDialogs presentRequestsDialogModallyWithSession:无
消息:自getInviteFriendMessage]
标题:无
参数:PARAMS
处理:^(FBWebDialogResult结果,NSURL * resultURL,NSError *误差)
{
如果(错误)
{
[个体经营requestFailedWithError:错误]
}
其他
{
如果(结果== FBWebDialogResultDialogNotCompleted)
{
[个体经营requestFailedWithError:无];
}
否则,如果([resultURL说明】有preFIX:@fbconnect://成功申请=])
{
// Facebook的返回FBWebDialogResultDialogCompleted甚至用户
// presses取消按钮,所以我们区分它的基础上,
// URL值,因为它会返回请求当我们真正
//完成对话
[个体经营requestSucceeded]
}
其他
{
//用户取消对话框
[个体经营requestFailedWithError:无];
} }
}];
}
其他
{
[个体经营requestFailedWithError:错误]
}
}];
}}
和这里是调用函数代表的辅助功能 OnFBSuccess
和 OnFBFailed
。
- (无效)requestSucceeded
{
的NSLog(@requestSucceeded);
ID所有者= [fbDelegate类]
SEL选择= NSSelectorFromString(@OnFBSuccess);
NSMethodSignature * SIG = [所有者instanceMethodSignatureForSelector:选择];
_callback = [NSInvocation的invocationWithMethodSignature:SIG];
[_callback setTarget:所有者];
[_callback setSelector:选择];
[_callback保留] [_callback invokeWithTarget:fbDelegate];
} - (无效)requestFailedWithError:(NSError *)错误
{
的NSLog(@requestFailed);
ID所有者= [fbDelegate类]
SEL选择= NSSelectorFromString(@OnFBFailed:);
NSMethodSignature * SIG = [所有者instanceMethodSignatureForSelector:选择];
_callback = [NSInvocation的invocationWithMethodSignature:SIG];
[_callback setTarget:所有者];
[_callback setSelector:选择];
[_callback setArgument:放大器;错误atIndex:2];
[_callback保留] [_callback invokeWithTarget:fbDelegate];
}
所以taht调用类的方法 InviteFriend
必须具有以下功能:
- (无效)OnFBSuccess
{
CCLOG(@成功); //在这里做的东西
[登录发布]
} - (无效)OnFBFailed:(NSError *)错误
{
如果(错误==无)
CCLOG(@用户取消);
其他
CCLOG(@失败); //在这里做的东西
[登录发布]
}
推荐阅读次数:
注意:
1),不要忘了安装Facebook应用程序ID在的plist
。
2)不要忘记调整的AppDelegate
来的处理的URL 。
从上面的链接2点采取局部片段:
/ *
*如果我们在通话的OpenURL的时候有效的会话,我们处理
* Facebook的转换通过传递URL参数handleOpenURL
* /
- (BOOL)应用:(*的UIApplication)的应用
的OpenURL:(NSURL *)网址
sourceApplication:(* NSString的)sourceApplication
注释:(ID)注释{
//尝试从URL中提取令牌
返回[FBSession.activeSession handleOpenURL:URL]
}
希望它帮助!
修改
下面:
声明fbDelegate是:
@属性(非原子,分配)ID&LT; FBLoginDelegate&GT; fbDelegate;@protocol FBLoginDelegate&LT;&NSObject的GT;@需要 - (无效)OnFBSuccess;
- (无效)OnFBFailed:(NSError *)错误;@结束
,这是你可以如何消费这一code:
FBLoginHandler *登录= [[FBLoginHandler页头] initWithDelegate:个体经营]; //这里的自我是你问的fbDelegate
[登录inviteFriends]
When I use the webdialog for a friendrequest, everything is going fine, except no request or anything is made. The code:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
facebookFriend.id, @"to",
nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:FBSession.activeSession
message:NSLocalizedString(@"FB_FRIEND_INVITE_MESSAGE", @"Facebook friend invite message")
title:NSLocalizedString(@"FB_FRIEND_INVITE_TITLE", @"Facebook friend invite title")
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
}];
This is the result I get:
fbconnect://success?request=xxxxxxxxxxxx&to%5B0%5D=xxxxxxxx
How can I debug what is going wrong?
Thanks in advance.
Ruud
For SDK 3.2 or above we have a facility to use FBWebDialogs class that will help us to show a popup along with the friend list and pick one or more from list to send invitation.
Lets do it step by step:
1) Download and setup SDK 3.2 or above.
2) First setup your application on facebook by following this url.
3) Then use the attached code.
Sample Code: (It generates invite friend request)
-(void)inviteFriends
{
if ([[FBSession activeSession] isOpen])
{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[self getInviteFriendMessage]
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error)
{
[self requestFailedWithError:error];
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
[self requestFailedWithError:nil];
}
else if([[resultURL description] hasPrefix:@"fbconnect://success?request="])
{
// Facebook returns FBWebDialogResultDialogCompleted even user
// presses "Cancel" button, so we differentiate it on the basis of
// url value, since it returns "Request" when we ACTUALLY
// completes Dialog
[self requestSucceeded];
}
else
{
// User Cancelled the dialog
[self requestFailedWithError:nil];
}
}
}
];
}
else
{
/*
* open a new session with publish permission
*/
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_stream"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
{
if (!error && status == FBSessionStateOpen)
{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[self getInviteFriendMessage]
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error)
{
[self requestFailedWithError:error];
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
[self requestFailedWithError:nil];
}
else if([[resultURL description] hasPrefix:@"fbconnect://success?request="])
{
// Facebook returns FBWebDialogResultDialogCompleted even user
// presses "Cancel" button, so we differentiate it on the basis of
// url value, since it returns "Request" when we ACTUALLY
// completes Dialog
[self requestSucceeded];
}
else
{
// User Cancelled the dialog
[self requestFailedWithError:nil];
}
}
}];
}
else
{
[self requestFailedWithError:error];
}
}];
}
}
and here are the helper functions that calls delegates function OnFBSuccess
and OnFBFailed
.
- (void)requestSucceeded
{
NSLog(@"requestSucceeded");
id owner = [fbDelegate class];
SEL selector = NSSelectorFromString(@"OnFBSuccess");
NSMethodSignature *sig = [owner instanceMethodSignatureForSelector:selector];
_callback = [NSInvocation invocationWithMethodSignature:sig];
[_callback setTarget:owner];
[_callback setSelector:selector];
[_callback retain];
[_callback invokeWithTarget:fbDelegate];
}
- (void)requestFailedWithError:(NSError *)error
{
NSLog(@"requestFailed");
id owner = [fbDelegate class];
SEL selector = NSSelectorFromString(@"OnFBFailed:");
NSMethodSignature *sig = [owner instanceMethodSignatureForSelector:selector];
_callback = [NSInvocation invocationWithMethodSignature:sig];
[_callback setTarget:owner];
[_callback setSelector:selector];
[_callback setArgument:&error atIndex:2];
[_callback retain];
[_callback invokeWithTarget:fbDelegate];
}
So the class taht calls method InviteFriend
MUST have these functions:
-(void)OnFBSuccess
{
CCLOG(@"successful");
// do stuff here
[login release];
}
-(void)OnFBFailed:(NSError *)error
{
if(error == nil)
CCLOG(@"user cancelled");
else
CCLOG(@"failed");
// do stuff here
[login release];
}
Recommended Reads:
NOTE:
1) Don't forget to setup Facebook application ID in plist
.
2) Don't forget to adjust AppDelegate
to handle urls.
Partial snippet taken from above link in point 2:
/*
* If we have a valid session at the time of openURL call, we handle
* Facebook transitions by passing the url argument to handleOpenURL
*/
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBSession.activeSession handleOpenURL:url];
}
Hope it helps!
EDIT
Here:
declaration for fbDelegate is:
@property (nonatomic, assign) id <FBLoginDelegate> fbDelegate;
@protocol FBLoginDelegate <NSObject>
@required
-(void) OnFBSuccess;
-(void) OnFBFailed : (NSError *)error;
@end
and this is how you can consume this code:
FBLoginHandler *login = [[FBLoginHandler alloc] initWithDelegate:self]; // here 'self' is the fbDelegate you have asked about
[login inviteFriends];
这篇关于presentRequestsDialogModallyWithSession不起作用,但给人好的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!