Skip to content

Commit

Permalink
Refactor common publish code in HelloFacebook Sample for iOS Sdk 3.0 …
Browse files Browse the repository at this point in the history
…(for ios 6)

Summary: Refactor common publish code in HelloFacebook Sample for iOS Sdk 3.0 (for ios 6)

Test Plan:
Verified both post actions in ios6.0 simulator.

Revert Plan:

Reviewers: jacl, gregschechte

Reviewed By: gregschechte

Differential Revision: https://phabricator.fb.com/D580174

Task ID: 1749352
  • Loading branch information
chrisp-fb committed Sep 20, 2012
1 parent 0207292 commit 644a659
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions samples/HelloFacebookSample/HelloFacebookSample/HFViewController.m
Expand Up @@ -52,6 +52,8 @@ @implementation HFViewController
@synthesize loggedInUser = _loggedInUser;
@synthesize profilePic = _profilePic;

#pragma mark - UIViewController

- (void)viewDidLoad {
[super viewDidLoad];

Expand Down Expand Up @@ -86,6 +88,8 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}
}

#pragma mark - FBLoginViewDelegate

- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
// first get the buttons set for login mode
self.buttonPostPhoto.enabled = YES;
Expand Down Expand Up @@ -116,8 +120,10 @@ - (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView {
self.labelFirstName.text = nil;
}

// Post Status Update button handler
- (IBAction)postStatusUpdateClick:(UIButton *)sender {
#pragma mark -

// Convenience method to perform some action that requires the "publish_actions" permissions.
- (void) performPublishAction:(void (^)(void)) action {
// we defer request for permission to post to the moment of post, then we check for the permission
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
// if we don't already have the permission, then we request it now
Expand All @@ -126,14 +132,21 @@ - (IBAction)postStatusUpdateClick:(UIButton *)sender {
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// re-call ourselves assuming we now have the necessary permission
[self postStatusUpdateClick:sender];
action();
}
//For this example, ignore errors (such as if user cancels).
}];
} else {
action();
}

}

// Post Status Update button handler
- (IBAction)postStatusUpdateClick:(UIButton *)sender {
[self performPublishAction:^{
// Post a status update to the user's feed via the Graph API, and display an alert view
// with the results or an error.

NSString *message = [NSString stringWithFormat:@"Updating %@'s status at %@",
self.loggedInUser.first_name, [NSDate date]];

Expand All @@ -145,24 +158,12 @@ - (IBAction)postStatusUpdateClick:(UIButton *)sender {
}];

self.buttonPostStatus.enabled = NO;
}
}];
}

// Post Photo button handler
- (IBAction)postPhotoClick:(UIButton *)sender {
// we defer request for permission to post to the moment of post, then we check for the permission
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
// if we don't already have the permission, then we request it now
[FBSession.activeSession reauthorizeWithPermissions:[NSArray arrayWithObject:@"publish_actions"]
behavior:FBSessionLoginBehaviorWithFallbackToWebView
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// re-call ourselves assuming we now have the necessary permission
[self postPhotoClick:sender];
}
}];
} else {
[self performPublishAction:^{
// Just use the icon image from the application itself. A real app would have a more
// useful way to get an image.
UIImage *img = [UIImage imageNamed:@"Icon-72@2x.png"];
Expand All @@ -174,7 +175,7 @@ - (IBAction)postPhotoClick:(UIButton *)sender {
}];

self.buttonPostPhoto.enabled = NO;
}
}];
}

// Pick Friends button handler
Expand Down

0 comments on commit 644a659

Please sign in to comment.