当我使用webdialog的friendrequest,一切都进展正常,但没有要求或任何制成。 代码:
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) {
}];
这是结果我得到:
fbconnect://success?request=xxxxxxxxxxxx&to%5B0%5D=xxxxxxxx
如何调试什么错误?
提前致谢。
范尼
对于SDK 3.2或以上 ,我们有一个工厂使用FBWebDialogs类,这将有助于我们展现出一个弹出与好友列表一起,并选择一个或多个从列表发送邀请。
让你一步一步来:
1)下载和安装SDK 3.2或以上。
2)首次设置按照您的Facebook应用程序这个网址。
3)然后,使用附加的代码。
示例代码:(它生成邀请好友请求)
-(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];
}
}];
}
}
这里是调用委托功能的辅助功能OnFBSuccess
和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];
}
所以taht调用方法的类InviteFriend
必须具有以下功能:
-(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];
}
推荐阅读次数:
通过Facebook发送邀请
API权限
一个例子
注意:
1)不要忘记安装Facebook应用程序ID中plist
。
2)不要忘记调整AppDelegate
来处理的URL 。
从上面的链接在点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];
}
希望能帮助到你!
编辑
这里:
声明fbDelegate是:
@property (nonatomic, assign) id <FBLoginDelegate> fbDelegate;
@protocol FBLoginDelegate <NSObject>
@required
-(void) OnFBSuccess;
-(void) OnFBFailed : (NSError *)error;
@end
这是如何可以消耗这样的代码:
FBLoginHandler *login = [[FBLoginHandler alloc] initWithDelegate:self]; // here 'self' is the fbDelegate you have asked about
[login inviteFriends];
我想你的应用程序没有启用的Android和网络。 而你试图让网络或Android设备的通知。
要点:有关Android或在网络上获得通知,您必须启用适用于Android和Web应用程序了。
启用Android和网络上你的App:转到您的应用程序>设置>点击+添加平台添加输入必要的信息,并保存。
让我们享受的通知。 :-)
文章来源: presentRequestsDialogModallyWithSession does not work, but gives good result