How do I customize a UIActivityViewController to show a URL link when posting to facebook and twitter?

后端 未结 4 1267
礼貌的吻别
礼貌的吻别 2020-12-14 07:08

So I\'m trying out the new UIActivityViewController in iOS 6, and it\'s really easy to get up and running, but I can\'t figure out how to control it like I want

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 07:44

    - (void)tweetURL:(NSString *)url title:(NSString *)title {
        TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
        NSString *format = @"“%@” %@ /via @DesignSceneApp";
        NSString *message = [NSString stringWithFormat:format, title, url]
        NSUInteger idx = title.length;
        while (![twitter setInitialText:message]) {
            idx -= 5;
            if (idx > 5) {
                message = [NSString stringWithFormat:format,
                    [NSString stringWithFormat:@"%@…", [title substringToIndex:idx]],
                    url
                ];
            } else {
                // Give up on the title.
                message = [NSString stringWithFormat:@"%@ /via @DesignSceneApp", url];
                [twitter setInitialText:message];
                break;
            }
        }
    
        [self presentViewController:twitter animated:YES completion:nil];
    }
    

提交回复
热议问题