Reputation: 203
I am trying to invite users in Facebook to try my iOS app (which is not in the store yet, didn't finish it yet).
I use facebook API to authenticate a user and then try to use the following code:
- (void)shareWithFriends:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Invite Friends"
message:@"If you enjoy using this app, would you mind taking a moment to invite a few friends that you think will also like it?"
delegate:self
cancelButtonTitle:@"No Thanks"
otherButtonTitles:@"Tell Friends!", nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView
didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
// User has clicked on the No Thanks button, do not ask again
NSLog(@"Chitty user says he doesn't wanna share");
} else if (buttonIndex == 1) {
// User has clicked on the Tell Friends button
[self performSelector:@selector(sendRequest) withObject:nil afterDelay:0.5];
}
}
- (void)sendRequest {
// Display the requests dialog
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[NSString stringWithFormat:@"Try this app, brah!"]
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Case A: Error launching the dialog or sending request.
NSLog(@"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// Case B: User clicked the "x" icon
NSLog(@"User canceled request.");
} else {
NSLog(@"Request Sent.");
}
}}];
}
However, when I select users to who I want to send the invites to and then hit Send. Nothing happens. I do get "Request Sent." through NSLog but my friend is not receiving it.
Any ideas?
Upvotes: 8
Views: 4624
Reputation: 11
How do you know you the request has not reached to other users? You must know they will not get any notification , they can access to it by going to this link :
You must have a Facebook app in your app as a platform with a canvas page. Then the users will get notification.
Upvotes: 0
Reputation: 9912
It always depends on the platforms your app is on. For example: if you have an app that is only available on mobile, the invited friends will only see the request on their phones and not on facebook.com. If you also have a canvas app on facebook.com, it will also appear on facebook.com.
You can read more about it in the documentation about the "Receive Experience" [1] of Requests sent by apps.
[1] https://developers.facebook.com/docs/games/requests/v2.0#receive
Upvotes: 0
Reputation: 774
I noticed that the notification message is only coming in Facebook App both Android/iOS, however web user can't see it, I hope it is not an implementation from Facebook? Also to make sure that your inviation(s) are successfully sent you have to parse the resultURL query.
NSDictionary *parameters = @{@"to":@""};
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:SL_FB_INVITE_DESCRIPTION
title:SL_FB_INVITE_TITLE
parameters:parameters
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if(error)
{
NSLog(@"Some errorr: %@", [error description]);
UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"Invitiation Sending Failed" message:@"Unable to send inviation at this Moment, please make sure your are connected with internet" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alrt show];
[alrt release];
}
else
{
if (![resultURL query])
{
return;
}
NSDictionary *params = [self parseURLParams:[resultURL query]];
NSMutableArray *recipientIDs = [[[NSMutableArray alloc] init] autorelease];
for (NSString *paramKey in params)
{
if ([paramKey hasPrefix:@"to["])
{
[recipientIDs addObject:[params objectForKey:paramKey]];
}
}
if ([params objectForKey:@"request"])
{
NSLog(@"Request ID: %@", [params objectForKey:@"request"]);
}
if ([recipientIDs count] > 0)
{
//[self showMessage:@"Sent request successfully."];
//NSLog(@"Recipient ID(s): %@", recipientIDs);
UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Invitation(s) sent successfuly!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alrt show];
[alrt release];
}
}
}
friendCache:nil];
- (NSDictionary *)parseURLParams:(NSString *)query
{
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease];
for (NSString *pair in pairs)
{
NSArray *kv = [pair componentsSeparatedByString:@"="];
[params setObject:[[kv objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
forKey:[[kv objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
return params;
}
Upvotes: 4
Reputation: 351
When are you populating params?
I know the FB API kindly sends a completed action if you send a blank facebook username as the recipient
Upvotes: 0