0

在 Facebook SDK 3.5 中,我尝试使用以下代码发送应用请求

Facebook 应用程序设置

列表设置

    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 通知,则不会发送通知。任何帮助表示赞赏....

4

2 回答 2

1

我已经在设置中配置了“Facebook 上的应用程序”和“本机 iOS 应用程序”配置,现在通知正在发送到 iOS 和 Web 应用程序(facebook)。

如果通知没有发送到 iOS Goto App--> Edit Settings--> App Details 并根据您的需要将类别更改为游戏/业务。现在通知将发送到您的桌面 Facebook 以及 iOS。

我也尝试过“Native Android App”配置来将我的通知发送到桌面、iOS 和 android,但到目前为止还没有运气。我认为android设置有问题。如果有人有答案,请告诉我。

于 2013-06-18T11:09:43.413 回答
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");
}

我希望它可以帮助你。

于 2013-06-04T07:34:47.450 回答