通过ios 8活动视图控制器在Facebook和Twitter上共享

时间:2015-04-27 09:48:14

标签: ios facebook twitter ios8 uiactivityviewcontroller

我在共享按钮中有代码执行此操作:

NSString *aText = _textToOutput;
UIImage *aPhoto = [[UIImage alloc] initWithData: _photoData];
NSURL *website = [NSURL URLWithString:@"http://www.google.com/"];



NSArray *objectsToShare = @[aText, aPhoto, website];

/* NSArray *includeActivities = @[UIActivityTypeMessage,
                               UIActivityTypeMail,
                               UIActivityTypePostToFacebook,
                               UIActivityTypePostToTwitter,
                               UIActivityTypePostToFlickr]; */    

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];

NSArray *excludeActivities = @[UIActivityTypeAirDrop,
                               UIActivityTypeCopyToPasteboard,
                               UIActivityTypePrint,
                               UIActivityTypeAssignToContact,
                               UIActivityTypeSaveToCameraRoll,
                               UIActivityTypeAddToReadingList,
                               UIActivityTypePostToFlickr,
                               UIActivityTypePostToVimeo];

activityVC.excludedActivityTypes = excludeActivities;

[self presentViewController:activityVC animated:YES completion:nil];

}

但是我能够通过短信和电子邮件发送所有3个要分享的对象。但是在Twitter上,URL没有出现在弹出窗口中,并且在Facebook上弹出窗口中缺少URL和NSString。 ios或这些应用程序有什么变化吗?感谢。

1 个答案:

答案 0 :(得分:4)

我正在使用以下代码在我的应用中分享。 它可能对你有所帮助。

代码是:

 UIImage *screenshotTaken = @"Image Url";

NSString *message = @"My Application Name";
NSString *shareBody =@"put Link Here";

// NSLog(@"%@",shareBody);
NSArray *postItems = @[message,shareBody,screenshotTaken];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
                                        initWithActivityItems:postItems
                                        applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];

iphone上的这个共享帖子默认设置。它在facebook,twitter,Flickr和电子邮件上共享。