开发者

How to share the status on facebook form iphone app

i want to post a string to the facebook wall from my iphone app like.. sharing the status in facebook.

presently i am doing like..wh开发者_运维百科en i press a button after logging in, i am getting a webview with the string i want to post and with buttons 'post' and 'cancel'.

but i want like.. when i click the first button only(after logging in, with out the facebook webview) the string should be posted to the wall.


Have you checked http://developers.facebook.com/docs/guides/mobile? Facebook has an SDK for all you need.


Add Social.Framework, then add below code

    {
     if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
     {
         SLComposeViewController *FacebookSheet = [SLComposeViewController        
composeViewControllerForServiceType:SLServiceTypeFacebook];
         [FacebookSheet setInitialText:@"Your text"];
         [FacebookSheet addURL:your url];
         [FacebookSheet addImage:[UIImage imageNamed:@"image.png"]];    
         [FacebookSheet setCompletionHandler:^(SLComposeViewControllerResult result) 
         {
            switch (result) 
            {
             case 0:
             {
               SLComposeViewControllerResultCancelled:
                NSLog(@"Post Canceled");
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Cancelled"
                 message:@"You must be connected to the internet to use this app."
                  delegate:nil
                   cancelButtonTitle:@"OK"
                    otherButtonTitles:nil];
                     [alert show];
               break;
             }
             case 1:
             {
               SLComposeViewControllerResultDone:
               NSLog(@"Post Sucessful");
               UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Successful"
                             message:@"Posted successfully."
                             delegate:nil
                             cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
                              [alert show];
               break;
               }
               default:
               break;
              }      
              }];
             [self presentViewController:FacebookSheet animated:YES completion:nil];
            }
            else
            {
               UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"No facebook accounts"      message:@"There are no facebook accounts configured. You can add or create a facebook account in phone settings." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];
            }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜