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

后端 未结 5 1209
抹茶落季
抹茶落季 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: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 
    

    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];
        }
    }
    

提交回复
热议问题