在Facebook SDK 3.5中,我正在尝试使用以下代码发送应用请求
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:@"Join"
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error)
{
NSLog(@"request error");
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
NSLog(@"request FBWebDialogResultDialogNotCompleted");
}
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
NSLog(@"request success");
}
else
{
// User Cancelled the dialog
NSLog(@"request cancelled");
}
}
}
];
如果我使用上面的代码与Facebook样本FacebookAppID,URL类型,FacebookDisplayName它工作正常。
但是,如果我提供自己的acebookAppID,URL类型,FacebookDisplayName,则不会传递通知。 任何帮助表示赞赏....
答案 0 :(得分:1)
我在设置中配置了“App on Facebook”和“Native iOS App”配置,现在通知正在发送到iOS和Web App(facebook)。
如果未将通知发送到iOS Goto App - >修改设置 - >应用详细信息,并根据您的需要将类别更改为游戏/商家。现在,通知将被发送到您的桌面Facebook和iOS。
我已尝试过“原生Android应用程序”配置,以便将我的通知发送到桌面,iOS和Android,但截至目前还没有运气。我认为Android设置存在问题。请告诉我是否有人有答案。
答案 1 :(得分:0)
试试这个: -
1.>首先按照Facebook url在Facebook上设置您的应用程序。
2>然后使用此代码并根据您的要求进行修改。
-(void)inviteFriends
{
if ([[FBSession activeSession] isOpen])
{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:@"put your message here"
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];
}
}];
}
}
请检查您的应用检查权限。如果未分配权限,请在您的应用中随意分配权限
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:/*assign permission here*/ nil];
这里是调用委托函数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];
}
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];
}
- (void)requestFailedWithError:(NSError *)error
{
if(error == nil)
CCLOG(@"user cancelled");
else
CCLOG(@"failed");
}
我希望它可以帮到你。