简体   繁体   English

如何在Facebook形式的iPhone应用程序上共享状态

[英]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. 我想从我的iPhone应用程序将一个字符串发布到Facebook墙上,例如..在Facebook中共享状态。

presently i am doing like..when 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'. 目前我正在做..当我登录后按一个按钮时,我正在获取一个包含要发布的字符串以及按钮“ post”和“ cancel”的webview。

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. 但是我想..当我仅单击第一个按钮时(登录后,没有使用Facebook webview),字符串应发布到墙上。

Have you checked http://developers.facebook.com/docs/guides/mobile ? 您是否检查过http://developers.facebook.com/docs/guides/mobile Facebook has an SDK for all you need. Facebook提供了您所需的所有SDK。

Add Social.Framework, then add below code 添加Social.Framework,然后添加以下代码

    {
     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];
            }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM