iPhone Dev
iPhone Dev

Reputation: 49

Facebook integration using parse framework

I done Facebook integration using parse framework with my application so how can i add logout button as well as permission to the user below mentioned image is my application screen-short as well how can i obtain okay button pressed event in my code..?

this is my application main screen after login

Upvotes: 1

Views: 2095

Answers (1)

HighFlyingFantasy
HighFlyingFantasy

Reputation: 3789

Login
In your app delegate, these lines should be present:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Parse setApplicationId:@"YOUR_APPLICATION_ID"
              clientKey:@"YOUR_CLIENT_KEY"];
[PFFacebookUtils initializeWithApplicationId:@"YOUR_FB_APP_ID"];

// Override point for customization after application launch.
return YES;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [PFFacebookUtils handleOpenURL:url];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [PFFacebookUtils handleOpenURL:url];
}

This will ensure that parse is initialized and connected with your facebook app on startup. The two methods at the bottom are what enables your app to launch the screen to sign in to facebook and request permissions. In order to actually present that screen to the user, all that's necessary is a button that calls a method similar to this one:

-(IBAction)facebookLoginButtonPressed:(id)sender {
    [self loginWithFacebook];
}

-(void)loginWithFacebook {
    NSArray *permissionsArray = @[@"publish_actions", @"email", @"user_location"];

    // Login PFUser using Facebook
    [PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {

        if (!user) {
            if (!error) {
                NSLog(@"Uh oh. The user cancelled the Facebook login.");
            } else {
                NSLog(@"Uh oh. An error occurred: %@", error);
            }
        } else {
            [self performSegueWithIdentifier:@"loginToFeed" sender:self];
        }
    }];
}

You shouldn't need an event callback for the ok, when the [PFFacebookUtils logInWithPermissions:block:] comes back, it will perform the block that you provide, enabling you to segue to different ViewControllers or show different features.

Log Out
Add a button to whatever view you want to have control logging out. Then add an IBAction method for that button:

-(IBAction)logOutButtonPressed:(id)sender {
    [PFUser logOut];
    NSLog(@"User logged out!");
    [self dismissViewControllerAnimated:YES completion:^{}];
}

Upvotes: 7

Related Questions