2

当我尝试在 ios 6 上显示共享对话框时,我的应用程序没有显示 FBNativeDialogs!

我正在使用 DEFacebookComposeViewController 库,在 ios 4.3、5.0 和 5.1 上没关系,在应用程序获取 facebooktoken 后出现对话框。但在 iOS 6 上,如果应用程序具有 facebook 令牌(我的意思是应用程序已经获得它,例如用户使用 facebook 登录),则不会出现对话框。只有在没有令牌然后它的工作时才会出现。并且使用 iOS 6 DEFacebookComposeViewController 它无法正常工作。FBNativeDialogs 返回错误代码 7。所以我的问题是如何在 iOS 6 上调用 DEFacebookComposeViewController,或者当已经有 facebook 令牌时如何使用 FBNativeDialogs。

 BOOL displayedNativeDialog = [FBNativeDialogs
 presentShareDialogModallyFrom:self
 initialText:@""
 image:nil
 url:[NSURL URLWithString:@"www.google.com"]
 handler:^(FBNativeDialogResult result, NSError *error) {

     // Only show the error if it is not due to the dialog
     // not being supporte, i.e. code = 7, otherwise ignore
     // because our fallback will show the share view controller.
     if (error && [error code] == 7) {
         return;
     }

     NSString *alertText = @"";
     if (error) {
         alertText = [NSString stringWithFormat:
                      @"error: domain = %@, code = %d",
                      error.domain, error.code];
     } else if (result == FBNativeDialogResultSucceeded) {
         alertText = @"Posted successfully.";
     }
     if (![alertText isEqualToString:@""]) {
         // Show the result in an alert
         [[[UIAlertView alloc] initWithTitle:@"Result"
                                     message:alertText
                                    delegate:self
                           cancelButtonTitle:@"OK!"
                           otherButtonTitles:nil]
          show];
     }
 }];

// Fallback, show the view controller that will post using me/feed
if (!displayedNativeDialog)
{
    UIDevice *device = [UIDevice currentDevice];
    CGFloat systemVersion = [[device systemVersion] floatValue];
    if (systemVersion > 5.5)
    {
        return;
    }
    DEFacebookComposeViewController *facebookViewComposer = [[DEFacebookComposeViewController alloc] init];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    [facebookViewComposer setInitialText:@""];
    [facebookViewComposer addURL:@"www.google.com"]];

    [facebookViewComposer setCompletionHandler:^(DEFacebookComposeViewControllerResult result) {
        switch (result) {
            case DEFacebookComposeViewControllerResultCancelled:
                NSLog(@"Facebook Result: Cancelled");
                break;
            case DEFacebookComposeViewControllerResultDone:
                NSLog(@"Facebook Result: Sent");
                break;
        }

        [facebookViewComposer dismissModalViewControllerAnimated:YES];
    }];
    [self presentModalViewController:facebookViewComposer animated:YES];

    [facebookViewComposer release];
}
4

1 回答 1

0

您需要在设备/模拟器上设置 Facebook 帐户(在 Settings->Facebook 下)。

更多细节: http: //facebook.stackoverflow.com/questions/12592898/facebook-sdk-3-1-presentsharedialogmodally-fails/12681352#12681352

于 2013-01-30T04:13:17.750 回答