rihekopo
rihekopo

Reputation: 3350

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.

Upvotes: 1

Views: 817

Answers (1)

SanitLee
SanitLee

Reputation: 1253

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.

Upvotes: 1

Related Questions