【问题标题】:IOS: Facebook integration - Sharing current url of UIwebviewIOS:Facebook 集成 - 共享 UIwebview 的当前 url
【发布时间】:2013-07-02 12:03:20
【问题描述】:

所以我正在制作一个新闻阅读器应用程序。它的来源是一个 RSS 提要,用户可以点击表格视图中呈现的故事。然后,这将在 Web 视图中打开故事。我为 Facebook 和 Twitter 设置了共享功能,但是我需要它来自动将 webview 的当前 url 添加到用户帖子中。对新手的任何帮助将不胜感激!

这是我的.m中的代码

- (IBAction)social:(id)sender {

    UIActionSheet *share = [[UIActionSheet alloc] initWithTitle:@"Pass on the news!" delegate:self cancelButtonTitle:@"OK" destructiveButtonTitle:nil otherButtonTitles:@"Post to Twitter", @"Post to Facebook", nil];

    //You must show the action sheet for the user to see it.
    [share showInView:self.view];
}

(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    //Each button title we gave to our action sheet is given a tag starting with 0.
    if (actionSheet.tag == 0) {

    //Check Twitter accessibility and at least one account is setup.
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {

        SLComposeViewController *tweetSheet =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

        //This is setting the initial text for our share card.
        [tweetSheet setInitialText:@"Check out this article I found using the 'Pass'  iPhone app: "];

        //Brings up the little share card with the test we have pre defind.
        [self presentViewController:tweetSheet animated:YES completion:nil];

    } else {
        //This alreat tells the user that they can't use built in socal interegration and why they can't.
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"You can't send a tweet right now, make sure you have at least one Twitter account setup and your device is using iOS6 or above!." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }

} else if (actionSheet.tag == 1) {

    //Check Facebook accessibility and at least one account is setup.
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        SLComposeViewController *facebookSheet =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        //This is setting the initial text for our share card.
        [facebookSheet setInitialText:@"Check out this article I found using the 'Pass'  iPhone app:"];

        //Brings up the little share card with the test we have pre defind.
        [self presentViewController:facebookSheet animated:YES completion:nil];

    } else {
        //This alreat tells the user that they can't use built in socal interegration and why they can't.
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"You can't post a Facebook post right now, make sure you have at least one Facebook account setup and your device is using iOS6 or above!." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];

【问题讨论】:

    标签: ios xcode facebook twitter uiwebview


    【解决方案1】:

    要提取您必须使用的网址名称:

    NSString *urlWeb = webViewName.request.URL.absoluteString
    

    如果你也想分享页面标题,你可以像这样使用 javascript:

    NSString *webTitle = [webViewName stringByEvaluatingJavaScriptFromString:@"document.title"];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-15
      • 2011-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-17
      • 2012-01-02
      • 2011-07-19
      相关资源
      最近更新 更多