Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7687689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:45:34+00:00 2026-05-31T19:45:34+00:00

I’m having trouble implementing the Facebook SDK in an iOS project. I am trying

  • 0

I’m having trouble implementing the Facebook SDK in an iOS project. I am trying to call it on a specific section of my app through a UIActionSheet. I am able to login to Facebook, but once redirected back to my app, the app does not register that it is logged in and can’t execute any of its sharing functions.

I have followed the Facebook iOS Tutorial at https://developers.facebook.com/docs/mobile/ios/build/ to include adding “fbMY_APP_ID” in the project info but can’t figure out why it won’t recognize that I am logged in.

Here is the relevant header and method I am using. For convenience, I’ve removed items unrelated to Facebook implementation:

//Header


#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import "MWFeedItem.h"
#import "FBConnect.h"


@interface DetailTableViewController : UITableViewController <UIAlertViewDelegate, UIActionSheetDelegate, UIApplicationDelegate, FBSessionDelegate>{

Facebook *facebook;
BOOL login;

}

@property (nonatomic, strong) Facebook *facebook;


@end

And the method:

//  Method

#import "DetailTableViewController.h"
#import "NSString+HTML.h"
#import <Twitter/Twitter.h>

@implementation DetailTableViewController

@synthesize facebook;

//Navigation button on detail view does THIS:

- (void)navAction {
    NSLog(@"Action sheet activated.");

    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                              initWithTitle:@"Like this story?" 
                              delegate:self 
                              cancelButtonTitle:@"Cancel" 
                              destructiveButtonTitle:@"Email link"
                              otherButtonTitles:@"Share on Facebook", @"Share on Twitter", @"Open in Safari", nil];

        [actionSheet showInView:[self.view window]];

}

-(void)actionSheet: (UIActionSheet *) actionSheet willDismissWithButtonIndex:(NSInteger) buttonIndex{

///////THIS SECTION DEFINES THE EMAIL SHARE FUNCTION/////


if (buttonIndex == 0) {

    // MFMailComposeViewController implementation

}


///////THIS SECTION DEFINES THE FACEBOOK SHARE FUNCTION/////

    else {
        if (buttonIndex == 1) {

            if (login == NO){

                NSLog(@"No login detected");

                UIAlertView *infoAlert = [[UIAlertView alloc]
                                          initWithTitle:@"Login necessary"
                                          message:@"You must first login to your Facebook account to use this feature." 
                                          delegate:self
                                          cancelButtonTitle:@"Login" 
                                          otherButtonTitles:@"Cancel", nil];
                [infoAlert show];
            }else {
                if (login == YES){

                NSLog(@"Login detected.");

                NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
                [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
                [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationKey"];
                [defaults synchronize];

                //APPLY LOGIN ACTION HERE. Waiting until I can make the system run the NSLog above. So far, the login is not being correctly recorded.

                }
            }


        }

        ///////THIS SECTION DEFINES THE TWITTER SHARE FUNCTION/////

        else {
        if (buttonIndex == 2) {

            //Twitter implementation here                
        }

    ///////THIS SECTION DEFINES THE SAFARI FUNCTION/////


        else{
            if (buttonIndex == 3){

            //Safari implementation here                    
            }

        }
        }   

    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
        {
            if (buttonIndex == 0)

            {

                // CALL TO FACEBOOK HERE

                facebook = [[Facebook alloc] initWithAppId:@"MY_APP_ID" andDelegate:self];

                NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

                if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]){
                    facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
                    facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];

                }

                if (![facebook isSessionValid]){

                    NSLog(@"Reached isSessionValid evaluation.");

                    [facebook authorize:nil];
                }

            }
            else if (buttonIndex == 1)
            {
                NSLog(@"Pressed cancel button");


            }
        }

// THIS METHOD SUPPORTS IOS PRE 4.2
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
return [facebook handleOpenURL:url];
}

// THIS METHOD SUPPORTS IOS AFTER 4.2
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
return [facebook handleOpenURL:url];
}


////////////////////////////////////////////

- (void)fbDidNotLogin:(BOOL)cancelled{

}

- (void)fbDidExtendToken:(NSString*)accessToken
           expiresAt:(NSDate*)expiresAt{

}

- (void)fbDidLogout{

}

- (void)fbSessionInvalidated{

}

- (void) fbDidLogin {

    NSLog(@"Logged in with Facebook credentials");

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationKey"];
    [defaults synchronize];

//APPLY LOGIN ACTION HERE. Waiting until I can make the system run the NSLog above. So far, the login is not being correctly recorded.

}

Additional info:

I’ve also tried adding the openURL portions to the main app delegate file but had the same results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:45:35+00:00Added an answer on May 31, 2026 at 7:45 pm

    Try this code in your project. I had a same issues which you have. Now my code is working perfect. Call your sharing method in your fbDidLogin method too. Dont forget to change your App id in code and also .plist File.

    -(void)buttonPressed:(id)sender{
    facebook = [[Facebook alloc] initWithAppId:@"YOUR_APP_ID" andDelegate:self];
    
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
                facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
                facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
            }
    if (![facebook isSessionValid]) {
        [facebook authorize:nil];
    }else{
    [self postWall];
    }
    // Pre 4.2 support
    - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
        return [facebook handleOpenURL:url]; 
    }
    - (void)fbDidLogin {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
        [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
        [defaults synchronize];
        [self postWall];
    }
    -(void)postWall{
    
        NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       @"https://developers.facebook.com/docs/reference/dialogs/",@"link",
                                       @"http://fbrell.com/f8.jpg",@"picture",
                                       @"Facebook Dialogs",@"name",
                                       @"Reference Documentation",@"caption",
                                       @"Using Dialogs to interact with users.",@"description",
                                       @"Facebook Dialogs are so easy!",@"message",
                                       nil];
    
        [[self facebook] dialog:@"feed" andParams:params andDelegate:self];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.