0

In Facebook SDK 3.5, I'm trying to send an App Request using the following code

Facebook App Settings

Plist Settings

    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....

Durga Vundavalli
  • 1,790
  • 22
  • 26
  • hi, please check your acebookAppID and change it every place where it has written – chandan Jun 04 '13 at 07:20
  • Check this link and set it according to it http://stackoverflow.com/questions/16052078/facebook-registration-the-operation-couldnt-be-completed-com-facebook-sdk-er/16052146?noredirect=1#comment22908493_16052146 – chandan Jun 04 '13 at 07:24
  • @chandan In settings i have not specified BundleID will that be a problem?? I don't have a distribution certificate right now... so i did not specify. – Durga Vundavalli Jun 04 '13 at 08:48
  • without BundleID you will not able to implement it becoz you need appId for it. And whenever you make any request , then this request create an url along with this bunddle-id as well as appid. So create a valid app id then go further. Thanks – chandan Jun 04 '13 at 08:53
  • Can i use development certificate for this purpose – Durga Vundavalli Jun 04 '13 at 08:55
  • yaa sure . And then create an valid app id with help of bundle identifier. – chandan Jun 04 '13 at 08:56
  • This is the warning i got when i edited the App Settings in Facebook ::Changes saved. Note that your changes may take several minutes to propagate to all servers. I tried with the BundleID as well but still no luck.... – Durga Vundavalli Jun 04 '13 at 09:49
  • Please have a look on my updated answer and follow this procedure. Thanks – chandan Jun 04 '13 at 10:17
  • Have a look at this thread http://stackoverflow.com/questions/15495462/presentrequestsdialogmodallywithsession-does-not-work-but-gives-good-result/16654666#16654666 I have updated answer. – NeverHopeless Jun 04 '13 at 12:25
  • @durga.chotu, please double check the SandBox mode when you setup application settings on facebook. – NeverHopeless Jun 04 '13 at 12:28
  • @charan I have updated with my BundleID, but still not working... I'm sure my BundleID is working because i'm able to install on the device using that BundleID and Developer certificate. – Durga Vundavalli Jun 05 '13 at 06:02
  • @NeverHopeless Sandbox mode was disabled.. i'm not using Delegate methods right now, just prininting a log on my console.. – Durga Vundavalli Jun 05 '13 at 06:05
  • @durga.chotu, so is your issue resolved ? if not using delegates then remove method calls like `[self requestSucceeded];` and replace it with `NSLog` if getting trouble in printing. – NeverHopeless Jun 05 '13 at 06:11
  • @NeverHopeless I have edited my question with some screen shots(App Settings and Plist) and Code to post a request.please have a look at it.I not able to post a request yet.. – Durga Vundavalli Jun 05 '13 at 06:19
  • What happens when you set SandBox mode to `Enable` in first image ? – NeverHopeless Jun 05 '13 at 06:22
  • @NeverHopeless I tried that as well, that was also not working – Durga Vundavalli Jun 05 '13 at 06:26
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/31229/discussion-between-neverhopeless-and-durga-chotu) – NeverHopeless Jun 05 '13 at 06:40
  • @durga.chotu, You are missing the setup for the section "App on Facebook". Try setting it up first. – NeverHopeless Jun 05 '13 at 06:52
  • @NeverHopeless I'm not using the App in Facebook, Is it needed to configure that option – Durga Vundavalli Jun 05 '13 at 10:00
  • @NeverHopeless Even configuring "App on Facebook" did not work.... Is it working in your apps??? – Durga Vundavalli Jun 06 '13 at 13:56
  • Yes it working in my three apps. – NeverHopeless Jun 06 '13 at 14:02
  • Have you step debugged the code and see if it passes from the path that has code for success case ? – NeverHopeless Jun 06 '13 at 14:03
  • @NeverHopeless this is the resutURL fbconnect://success?request=565267650190041&to%5B0%5D=1243011293 I even checked FBWebDialogResultDialogCompleted. but i don't see any notification in the mobile app – Durga Vundavalli Jun 07 '13 at 09:12
  • @NeverHopeless I think after configuring "App on Facebook" notification are being delivered to Facebook WEB application, but not on to Mobile App.(I'm able to see notifications on Web Application) – Durga Vundavalli Jun 07 '13 at 09:25
  • FB**Web**Dialogs is to send notification on web, push notifications is used to notify on the device. So it is working as expected. – NeverHopeless Jun 07 '13 at 09:42
  • If i use Facebook SDK example FacebookAppID(370546396320150) Notifications are delivered to Mobile App not to the web application – Durga Vundavalli Jun 07 '13 at 10:46
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/31393/discussion-between-neverhopeless-and-durga-chotu) – NeverHopeless Jun 07 '13 at 11:23

2 Answers2

1

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.

Durga Vundavalli
  • 1,790
  • 22
  • 26
0

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.

chandan
  • 2,453
  • 23
  • 31
  • if it is permissions problem, why it is working for FacebookAppID. what permissions we have give to post a request?? – Durga Vundavalli Jun 04 '13 at 08:52
  • @durga.chotu , first check with valid app id. If your app id is correct then further it might be permissions problem. – chandan Jun 04 '13 at 08:55
  • @chandan which permissions give for FriendRequest ?? – Raju Nov 16 '13 at 09:27
  • Hi @AppleMap , it is publish_stream permission that we will pass with session. Open a new session with publish permission which will allow user to post on his or her wall. – chandan Nov 18 '13 at 05:38