【问题标题】:How to share selected text from iphone book app on Facebook如何在 Facebook 上分享 iphone book 应用程序中的选定文本
【发布时间】:2014-01-19 10:35:19
【问题描述】:

我有 iphone book 应用程序,就像所有其他文本一样,当点击并按住特定单词时,您将看到(复制,定义)菜单,我想添加另一个项目,即(共享)当用户点击它时共享操作表将弹出,用户可以在(Facebook、Twitter、邮件或文本)上分享特定的单词。 请帮我详细说明,任何帮助将不胜感激。

【问题讨论】:

  • 您可以将选定的文本发布到用户的 Facebook 或 Twitter,也可以使用选定的文本创建邮件作为该电子邮件的正文。
  • Ad-J 你能给我一个示例代码吗?谢谢。
  • 有很多可用于 Facebook 和 twitter 集成的教程。您甚至可以使用 iDev 的答案并将 twitter 中的 intialText 和 facebook 部分中的描述替换为您选择的文本。

标签: ios iphone facebook sdk share


【解决方案1】:

社会框架:

share Fb or Twitter

- (IBAction)socialSheet:(id)sender {



       // create Facebook controller
        SLComposeViewController *socialController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        // add initial text
        [socialController setInitialText:@"Hello Facebook!"];

        // add an image for you optional 
        [socialController addImage:[UIImage imageNamed:@"picture.jpg"]];

        // add a URL for you optional 
        [socialController addURL:[NSURL URLWithString:@"http://wpguru.co.uk"]];

        // present controller
        [self presentViewController:socialController animated:YES completion:nil];
    }

Facebook 接口

  -(void) postWithText: (NSString*) message_text
               ImageName: (NSString*) image_name
                     URL: (NSString*) url
                 Caption: (NSString*) caption
                    Name: (NSString*) name
          andDescription: (NSString*) description
    {

        NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                       url, @"link",
                                       name, @"name",
                                       caption, @"caption",
                                       description, @"description",
                                       message, @"message_name",
                                       UIImagePNGRepresentation([UIImage imageNamed: image_name]), @"picture",
                                       nil];

        if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound)
        {
            // No permissions found in session, ask for it
            [FBSession.activeSession requestNewPublishPermissions: [NSArray arrayWithObject:@"publish_actions"]
                                                  defaultAudience: FBSessionDefaultAudienceFriends
                                                completionHandler: ^(FBSession *session, NSError *error)
            {
                 if (!error)
                 {
                     // If permissions granted and not already posting then publish the story
                     if (!m_postingInProgress)
                     {
                         [self postToWall: params];
                     }
                 }
             }];
        }
        else
        {
            // If permissions present and not already posting then publish the story
            if (!m_postingInProgress)
            {
                [self postToWall: params];
            }
        }
    }

    -(void) postToWall: (NSMutableDictionary*) params
    {
        m_postingInProgress = YES; //for not allowing multiple hits

        [FBRequestConnection startWithGraphPath:@"me/feed"
                                     parameters:params
                                     HTTPMethod:@"POST"
                              completionHandler:^(FBRequestConnection *connection,
                                                  id result,
                                                  NSError *error)
         {
             if (error)
             {
                 //showing an alert for failure
                 UIAlertView *alertView = [[UIAlertView alloc]
                                           initWithTitle:@"Post Failed"
                                           message:error.localizedDescription
                                           delegate:nil
                                           cancelButtonTitle:@"OK"
                                           otherButtonTitles:nil];
                 [alertView show];
             }
             m_postingInProgress = NO;
         }];
    }

【讨论】:

  • 感谢您的回答,我如何使用您的代码共享选定的单词。我想我需要用一些东西替换“Hello Facebook”,但我不知道它是什么,你能帮我吗?
  • @4slices 您想使用社交框架 else api 分享的话
  • 是的,我想选择特定的短语并分享它。
  • 检查我的答案和链接。图片和网址供您选择。如果不会忽略这一点
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多