简体   繁体   中英

How I can use Facebook login for login my app in iPhone?

I have an application in xcode 4, and I need to use the Facebook's username and password to authenticate and access my application. Only want to use Facebook login and Password for login to application. After login successful should be open our iPhone application. How I can do this?

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

    facebook = [[Facebook alloc] initWithAppId:@"211846395591747" 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];
    }

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

    NSLog(@"handleOpenURL");

    return [facebook handleOpenURL:url]; 
}

I did this code for Facebook connectivity. It's opening our Facebook developer's project page. i want only use Facebook username and password for login to my application. Please help me.

There are the facebook delegate methods for login and logout. First call login method at the start of application You can set BOOL variable to check if user logged in or not and based on that you can give the access to the user

您需要创建Bool方法来完成Facebook登录或未登录,您必须先设置此功能,如果未完成登录,则显示警报框,此链接可以解决您的应用程序使用Facebook登录的问题

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