简体   繁体   中英

How to setup Facebook iOS SDK properly with Parse in AppDelegate?

I'm trying to integrate Facebook to my Parse project, but I have problems with the new SDK version.

With the older versions I've just imported the related header files into my AppDelegate, pasted two methods and it worked well.

This is how I've done it:

//  AppDelegate.m
#import <Parse/Parse.h>
#import <ParseFacebookUtils/PFFacebookUtils.h>
#import <FacebookSDK/FacebookSDK.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


    [Parse setApplicationId:@"xy"
                  clientKey:@"xy"];
    [PFFacebookUtils initializeFacebook];

    [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];

    return YES;
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    return [FBAppCall handleOpenURL:url
                  sourceApplication:sourceApplication
                        withSession:[PFFacebookUtils session]];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {


    [FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];


}

But now the Facebook SDK contains several frameworks and it's not so clear which one is needed or not. Actually I'm trying the below code, but getting this error: Use of undeclared identifier 'PFFacebookUtils' .

  // AppDelegate.m
#import <Parse/Parse.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


    [Parse setApplicationId:@"xy"
                  clientKey:@"xy"];
    [PFFacebookUtils initializeFacebook];

    [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];

    return YES;
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                          openURL:url
                                                sourceApplication:sourceApplication
                                                       annotation:annotation];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [FBSDKAppEvents activateApp];
}

I would really appreciate if somebody could show me his own Fb sdk setup in the AppDelegate with Parse or explain me what did I wrong.

Here I share how I've integrated FB to my project with Parse.

AppDelegate.m

#import <ParseFacebookUtils/PFFacebookUtils.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  ...
  [PFFacebookUtils initializeFacebook]; // don't forget this. it's not mentioned in tutorial
  ...
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    return [FBAppCall handleOpenURL:url
                  sourceApplication:sourceApplication
                        withSession:[PFFacebookUtils session]];
}

- (void)applicationWillTerminate:(UIApplication *)application {
    [[PFFacebookUtils session] close];
}

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM