所以我正在制作新闻阅读器应用程序。它的来源是RSS提要,用户可以单击tableview中显示的故事。然后,这将在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];
答案 0 :(得分:1)
要提取您必须使用的网址名称:
NSString *urlWeb = webViewName.request.URL.absoluteString
如果你想分享页面标题,你可以使用这样的javascript:
NSString *webTitle = [webViewName stringByEvaluatingJavaScriptFromString:@"document.title"];