简体   繁体   中英

Open facebook dialog for authentication instead of Installed facebook app in iphone?

I want to made a app that ask to authenticate for facebook login in dialog either if facebook application is installed in iphone or not installed.And if I log out the facebook then it should logout from facebook. I have used facebook-ios-sdk for facebook api my code is as follows:

- (void)viewDidLoad
{
    _facebook=[[Facebook alloc] initWithAppId:appId andDelegate:self];

    self.navigationController.navigationBarHidden = YES;
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"])
    {
        _facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        _facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }

    [super viewDidLoad];
}

//login button tapped

-(IBAction)Login
{
    NSLog(@"login called");

    if (![self connected])
    {
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Connection" message:@"Internet is not Connected" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];[alert release];
    }
    else
    {
        if (suggestion==nil)
        {
            suggestion=[[Suggestions alloc] initWithNibName:@"Suggestions" bundle:nil];
        }
        [suggestion setReqFlg:YES];

        if (![_facebook isSessionValid]) 
        {
            NSLog(@"sesssion invalid u have to login...");
            [_facebook authorize:nil];
        }
        else
        {
            NSLog(@"valid and going on next page called graph API ");      

            [_facebook requestWithGraphPath:@"me?fields=id,name" andDelegate:self];
            suggestion.parentView=self;
            [self.navigationController pushViewController:suggestion animated:YES];
        }
    }
}



- (void)fbDidLogin
{
    NSLog(@"facebook did first login..");
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[_facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[_facebook expirationDate] forKey:@"FBExpirationDateKey"];  
    [defaults synchronize];
    NSLog(@"called gtraph from login in facebook ");
    [_facebook requestWithGraphPath:@"me?fields=id" andDelegate:self];
    if (suggestion==nil)
    {
        suggestion=[[Suggestions alloc] initWithNibName:@"Suggestions" bundle:nil];
    }
    suggestion.parentView=self;
    [self.navigationController pushViewController:suggestion animated:YES];
}

- (void)fbDidLogout
{
    NSLog(@"logout");
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [defaults removeObjectForKey:@"FBAccessTokenKey"];
    [defaults removeObjectForKey:@"FBExpirationDateKey"];
    [defaults removeObjectForKey:@"FBUserId"];

    [defaults synchronize];
}

Does I have to change in facebook.m file or there is another way to do this.Every time I clicked on login button should display facebook login dialog if facebook is logout and navigate to next view if facebook is login.Do not open facebook app installed in iphone for login purpose.

Give your reviews or answers I really need it. Thanks u!

its so simple go in facebook.m file, search with FBAppAuth and You got 3_4 result like:-

 [self authorizeWithFBAppAuth:YES safariAuth:YES];

just change YES to NO like:-

 [self authorizeWithFBAppAuth:NO safariAuth:NO];

change it in facebook.m only and compile and run you got fblogin dialog when you click on loginButton :)

edit

i got my login dialog on my app login page

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