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 7790137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:29:56+00:00 2026-06-01T21:29:56+00:00

I’m looking to use the Facebook Api to check in users in an iOS

  • 0

I’m looking to use the Facebook Api to check in users in an iOS app.

I was wondering if I have the permissions set in the AppDelegate but want the user to checkin from a different view controller do I have to declare the Facebook instance in every view controller along with the FBRequestDelegate, FBSessionDelegate, FBDialogDelegate delegate methods? or is it a one time thing in the AppDelegate?

thanks for any help.

  • 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-06-01T21:29:56+00:00Added an answer on June 1, 2026 at 9:29 pm

    I just dealt with the exact same problem. Here is my solution:

    I Created a FBRequestWrapper which basically contains the following methods:

    #import <Foundation/Foundation.h>
    #import "Facebook.h"
    
    #define FB_APP_ID @"xx"
    #define FB_APP_SECRET @"xx"
    
    @interface FBRequestWrapper : NSObject <FBRequestDelegate, FBSessionDelegate>
    {
        Facebook *facebook;
        BOOL isLoggedIn;
    }
    
    @property (nonatomic, retain) Facebook *facebook;
    @property (nonatomic, assign) BOOL isLoggedIn;
    
    + (id) defaultManager;
    - (void) setIsLoggedIn:(BOOL) _loggedIn;
    - (void) FBSessionBegin:(id) _delegate;
    - (void) FBLogout;
    - (void) getFBRequestWithGraphPath:(NSString*) _path andDelegate:(id) _delegate;
    - (void) sendFBRequestWithGraphPath:(NSString*) _path params:(NSMutableDictionary*) _params andDelegate:(id) _delegate;
    
    @end
    

    So all the Facebook stuff is managed in this Singleton class.

    In my AppDelegate I invoke the authentication. Because in my opinion the authentication has to be done before loading all the controllers.

    // FACEBOOK
    requestWrapper = [FBRequestWrapper defaultManager];
    
    BOOL loggedIn = [requestWrapper isLoggedIn];
    
    // if the user is not currently logged in begin the session
    if (!loggedIn) {
        [requestWrapper FBSessionBegin:(id)self];
    } else {
        NSLog(@"Is already logged in!");
    }
    
    // Check if the access token is already there. In that case the user is already authenticated with facebook.
    // Directly load the controllers and do not wait till facebook has returned back the access_token
    if([[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"] != nil &&
       [[NSUserDefaults standardUserDefaults] objectForKey:@"exp_date"] != nil) {
        [self loadControllers];
    }
    

    You can see that I also store the accessToken in the NSUserDefaults space. Because we are using the accessToken as authentication to our webservice.

    My AppDelegate method is delegating the FBSessionDelegate method:

    @interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate, FBSessionDelegate>
    

    And here is the implementation of the most important method, fbDidLogin:

    - (void) fbDidLogin {
        NSLog(@"AccessToken: %@", requestWrapper.facebook.accessToken);
    
        [[NSUserDefaults standardUserDefaults] setObject:requestWrapper.facebook.accessToken forKey:@"access_token"];
        [[NSUserDefaults standardUserDefaults] setObject:requestWrapper.facebook.expirationDate forKey:@"exp_date"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    
        [self loadControllers];
    }
    

    Here I store the accesstoken in the NSUserDefaults and load all the Controllers if everything was fine.

    Now if you want to access the Facebook Graph Api from any controller outside the AppDelegate you can also use the FBRequestWrapper like that:

    - (IBAction)test:(id)sender {
       // FBRequestWrapper
       NSString *graphPath = @"me/friends";
    
       [[FBRequestWrapper defaultManager] getFBRequestWithGraphPath:graphPath andDelegate:self];
    }
    

    Here the code from the FBRequestWrapper.m:

    #import "FBRequestWrapper.h"
    
    static FBRequestWrapper *defaultWrapper = nil;
    
    @implementation FBRequestWrapper
    @synthesize isLoggedIn, facebook;
    
    + (id) defaultManager {
    
        if (!defaultWrapper)
            defaultWrapper = [[FBRequestWrapper alloc] init];
    
        return defaultWrapper;
    }
    
    - (void) setIsLoggedIn:(BOOL) _loggedIn {
        isLoggedIn = _loggedIn;
    
        if (isLoggedIn) {
            [[NSUserDefaults standardUserDefaults] setObject:facebook.accessToken forKey:@"access_token"];
            [[NSUserDefaults standardUserDefaults] setObject:facebook.expirationDate forKey:@"exp_date"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
        else {
            [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"access_token"];
            [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"exp_date"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
    }
    
    - (void) FBSessionBegin:(id) _delegate {
    
        if (facebook == nil) {
            facebook = [[Facebook alloc] initWithAppId:FB_APP_ID andDelegate:_delegate];
            [facebook setSessionDelegate:_delegate];
    
            NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"];
            NSDate *exp = [[NSUserDefaults standardUserDefaults] objectForKey:@"exp_date"];
    
            if (token != nil && exp != nil && [token length] > 2) {
                isLoggedIn = YES;
                facebook.accessToken = token;
                facebook.expirationDate = [NSDate distantFuture];
    
                [self setIsLoggedIn:isLoggedIn];
    
                NSLog(@"Access token: %@", facebook.accessToken);
            } 
        }
    
        if(![facebook isSessionValid]) {
            NSArray *permissions = [NSArray arrayWithObjects:@"offline_access", @"read_friendlists", @"user_about_me", nil];
    
            // if no session is available login
            [facebook authorize:permissions];
        }
    }
    - (void) FBLogout {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"access_token"];
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"exp_date"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    
        [facebook logout:self];
    }
    
    // Make simple requests
    - (void) getFBRequestWithGraphPath:(NSString*) _path andDelegate:(id) _delegate {
        if (_path != nil) {
            [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    
            if (_delegate == nil)
                _delegate = self;
    
            if(isLoggedIn) {
                NSLog(@"is logged in in the get method");
            } else {
                NSLog(@"Is NOT logged in the get metthod");
            }
    
            [facebook requestWithGraphPath:_path andDelegate:_delegate];
        }
    }
    
    // Used for publishing
    - (void) sendFBRequestWithGraphPath:(NSString*) _path params:(NSMutableDictionary*) _params andDelegate:(id) _delegate {
    
        if (_delegate == nil)
            _delegate = self;
    
        if (_params != nil && _path != nil) {
    
            [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
            [facebook requestWithGraphPath:_path andParams:_params andHttpMethod:@"POST" andDelegate:_delegate];
        }
    }
    
    #pragma mark -
    #pragma mark FacebookSessionDelegate
    
    - (void)fbDidLogin {
        isLoggedIn = YES;
    
        [[NSUserDefaults standardUserDefaults] setObject:facebook.accessToken forKey:@"access_token"];
        [[NSUserDefaults standardUserDefaults] setObject:facebook.expirationDate forKey:@"exp_date"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    
    - (void)fbDidNotLogin:(BOOL)cancelled {
        isLoggedIn = NO;
    }
    
    - (void)fbDidLogout {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"access_token"];
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"exp_date"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    
        isLoggedIn = NO;
    }
    
    
    #pragma mark -
    #pragma mark FBRequestDelegate
    
    - (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
        //NSLog(@"ResponseFailed: %@", error);
    }
    
    - (void)request:(FBRequest *)request didLoad:(id)result {
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
        //NSLog(@"Parsed Response: %@", result);
    }
    
    
    /**
     * Called after the access token was extended. If your application has any
     * references to the previous access token (for example, if your application
     * stores the previous access token in persistent storage), your application
     * should overwrite the old access token with the new one in this method.
     * See extendAccessToken for more details.
     */
    - (void)fbDidExtendToken:(NSString*)accessToken expiresAt:(NSDate*)expiresAt {
        NSLog(@"Fb did extend token.. NOT IMPLEMENTED YET!");
    }
    
    /**
     * Called when the current session has expired. This might happen when:
     *  - the access token expired
     *  - the app has been disabled
     *  - the user revoked the app's permissions
     *  - the user changed his or her password
     */
    - (void)fbSessionInvalidated {
        NSLog(@"Fb session invalidated.. NOT IMPLEMENTED YET!");
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.