Reputation: 1828
In Facebook SDK 3.5, I'm trying to send an App Request using the following code
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");
}
}
}
];
if i use the above code with the Facebook sample FacebookAppID,URL types,FacebookDisplayName it's working fine.
But if i give my own acebookAppID,URL types,FacebookDisplayName the notifications were not delivered. Any help appreciated....
Upvotes: 0
Views: 2825
Reputation: 1828
I have configured "App on Facebook" and "Native iOS App" configurations in settings, Now the notifications are being delivered to iOS and Web App(facebook).
If the notifications are not being delivered to iOS Goto App--> Edit Settings--> App Details and change the category to games/business according to your need. Now the notifications will be delivered to your Desktop Facebook as well as iOS.
I have tried "Native Android App" configurations as well to deliver my notifications to desktop,iOS and android,but no luck as of now. I think there is a problem with android settings.please let me know if anyone have the answer.
Upvotes: 1
Reputation: 2453
Try this :-
1.>First setup your application on facebook by following Facebook url.
2.> Then use this code and modify according to your requirments.
-(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];
}
}];
}
}
Please check your app check permission. If permission not assign then please assign permissions whatever you want in your app
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:/*assign permission here*/ nil];
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];
}
- (void)requestFailedWithError:(NSError *)error
{
if(error == nil)
CCLOG(@"user cancelled");
else
CCLOG(@"failed");
}
i hope it helps you.
Upvotes: 0