Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is how I did it, in my ibaction method:</p> <p>Sharing Image:</p> <pre><code>UIImage *img = myImage; FBLoginView *loginview = [[FBLoginView alloc] init]; loginview.delegate = self; [self performPublishAction:^{ [FBRequestConnection startForUploadPhoto:img completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { [self showAlert:@"Photo Post" result:result error:error]; }]; }]; </code></pre> <p>Sharing URL:</p> <pre><code>NSURL *urlToShare = [NSURL URLWithString:@"http://developers.facebook.com/ios"]; FBAppCall *appCall = [FBDialogs presentShareDialogWithLink:urlToShare name:@"Hello Facebook" caption:nil description:@"The 'Hello Facebook' sample application showcases simple Facebook integration." picture:nil clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) { if (error) { NSLog(@"Error: %@", error.description); } else { NSLog(@"Success!"); } }]; </code></pre> <p>Add these as well:</p> <pre><code>- (void) performPublishAction:(void (^)(void)) action { if([[FBSession activeSession]isOpen]) { if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) { // if we don't already have the permission, then we request it now [FBSession.activeSession requestNewPublishPermissions:@[@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error) { if (!error) { action(); } //For this example, ignore errors (such as if user cancels). }]; } else { action(); } } else { [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { if (!error &amp;&amp; status == FBSessionStateOpen) { }else{ NSLog(@"Session error"); [self fbResync]; [NSThread sleepForTimeInterval:0.5]; //half a second [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error){ }]; } }]; } } - (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView { } - (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id&lt;FBGraphUser&gt;)user { self.loggedInUser = user; } - (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView { self.loggedInUser = nil; } -(void)fbResync { ACAccountStore *accountStore; ACAccountType *accountTypeFB; if ((accountStore = [[ACAccountStore alloc] init]) &amp;&amp; (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook] ) ){ NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB]; id account; if (fbAccounts &amp;&amp; [fbAccounts count] &gt; 0 &amp;&amp; (account = [fbAccounts objectAtIndex:0])){ [accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) { //we don't actually need to inspect renewResult or error. if (error){ } }]; } } } </code></pre> <p>Hope this helps... Look at HelloFacebookSample in Facebook SDK Samples.</p> <p>Try this:</p> <pre><code>[self performPublishAction:^{ NSString *message = [NSString stringWithFormat:@"Updating status for %@ at %@", self.loggedInUser.first_name, [NSDate date]]; [FBRequestConnection startForPostStatusUpdate:message completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { [self showAlert:message result:result error:error]; self.buttonPostStatus.enabled = YES; }]; self.buttonPostStatus.enabled = NO; }]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload