Supporting both iOS 5 and iOS 6 with the Facebook SDK 3.1

后端 未结 5 1208
抹茶落季
抹茶落季 2021-01-14 07:03

I have an app that currently supports posting to Facebook through the feed dialog using the old Facebook SDK for iOS.

After updating to the Facebook SDK 3.1 for iOS,

相关标签:
5条回答
  • 2021-01-14 07:09

    I think you will get an "duplicate error" if you use both. I know it sucks.

    Ive been messing with the duplicate error for days now. Please let me know if you got there.

    0 讨论(0)
  • 2021-01-14 07:10

    You'll probably have to abstract out a common interface and implement it twice in separate source files (so the compiler never sees Facebook.h and FacebookSDK.h in the same file).

    0 讨论(0)
  • 2021-01-14 07:17

    Just include Facebook.h instead. To do this first, Copy the DeprecatedHeaders folder into your Frameworks project. The DeprecatedHeaders are found under ~/Documents/FacebookSDK/FacebookSDK.frameworks/Versions/A/. When you copy it over do not copy the items into your project, so they stay copied as a reference.

    Next, in your code where you have:

    #import <FacebookSDK/FacebookSDK.h>
    

    Replace with this:

    #import "Facebook.h"
    

    You may get an error, in which case close and reopen the project.

    Next you want to declare a Facebook object and set the session or clear it whenever your Session is open or closed.

    Take as an example, the sample: https://github.com/fbsamples/ios-3.1-howtos/tree/master/ShareNativeDialogsHowTo that is documented here, https://developers.facebook.com/docs/howtos/share-native-dialogs-ios-sdk/

    You could make the following changes to that sample to fallback to the feed dialog instead of falling back to a view controller with a share UI. In ViewController.m you would make these changes after including the Facebook header:

    ....
    @property (unsafe_unretained, nonatomic) IBOutlet UIButton *publishButton;
    @property (nonatomic, retain) Facebook *facebook;
    
    ....
    @synthesize authButton;
    @synthesize facebook = _facebook;
    
    ....
    - (void)sessionStateChanged:(NSNotification*)notification {
        if (FBSession.activeSession.isOpen) {
            self.publishButton.hidden = NO;
            [self.authButton setTitle:@"Logout" forState:UIControlStateNormal];
            if (nil == self.facebook) {
                self.facebook = [[Facebook alloc]
                                 initWithAppId:FBSession.activeSession.appID
                                 andDelegate:nil];
                // Store the Facebook session information
                self.facebook.accessToken = FBSession.activeSession.accessToken;
                self.facebook.expirationDate = FBSession.activeSession.expirationDate;
            }
        } else {
            self.publishButton.hidden = YES;
            [self.authButton setTitle:@"Login" forState:UIControlStateNormal];
            self.facebook = nil;
        }
    }
    
    - (void) publishUsingFeedDialog {
        // Put together the dialog parameters
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       @"Facebook SDK for iOS", @"name",
                                       @"Build great social apps and get more installs.", @"caption",
                                       @"The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.", @"description",
                                       @"https://developers.facebook.com/ios", @"link",
                                       @"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png", @"picture",
                                       nil];
    
        // Invoke the dialog
        [self.facebook dialog:@"feed" andParams:params andDelegate:nil];
    }
    
    
    - (IBAction)publishButtonAction:(id)sender {
        BOOL displayedNativeDialog =
        [FBNativeDialogs
         presentShareDialogModallyFrom:self
         initialText:@""
        ....
    
        if (!displayedNativeDialog) {
            /*ShareViewController *viewController =
            [[ShareViewController alloc] initWithNibName:@"ShareViewController"
                                                  bundle:nil];
            [self presentViewController:viewController
                               animated:YES
                             completion:nil];*/
            [self publishUsingFeedDialog];
        }
    }
    
    0 讨论(0)
  • 2021-01-14 07:18

    Try to import

    "FBSession.h" 
    

    instead of

    #import<FacebookSDK/FacebookSDK.h>
    

    it will solve the duplicate error..

    0 讨论(0)
  • 2021-01-14 07:27

    It's impossible, you should use Graph API https://developers.facebook.com/docs/howtos/publish-to-feed-ios-sdk/ instead of Feed Dialog :(

    0 讨论(0)
提交回复
热议问题