我一直在寻找UIActivityViewController来分享不同类型的活动类型的不同字符串或图像,例如打印选项,共享选项(facebook,twitter)。
但没有做任何选择。请指教。
谢谢!
答案 0 :(得分:0)
试用此代码
-(void)shareContent{
NSString * message = @"My too cool Son";
UIImage * image = [UIImage imageNamed:@"boyOnBeach"];
NSArray * shareItems = @[message, image];
UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil];
[self presentViewController:avc animated:YES completion:nil];
}
答案 1 :(得分:0)
您可以使用UIActivityItemProvider
执行此操作 .h文件中的
@interface APActivityProvider : UIActivityItemProvider <UIActivityItemSource>
@end
.m文件中的
@implementation APActivityProvider
- (id) activityViewController:(UIActivityViewController *)activityViewController
itemForActivityType:(NSString *)activityType {
if ( [activityType isEqualToString:UIActivityTypePostToFacebook] )
return @"This is a facebook post!";
if ( [activityType isEqualToString:UIActivityTypeMessage] )
return @"SMS message text";
if ( [activityType isEqualToString:UIActivityTypeMail] )
return @"Email text here!";
}
- (void) shareAppData {
APActivityProvider *ActivityProvider = [[APActivityProvider alloc] initWithPlaceholderItem: @“”];
NSArray *Items = @[ActivityProvider];
UIActivityViewController *ActivityView = [[UIActivityViewController alloc]
initWithActivityItems:Items
applicationActivities:nil];
[ActivityView setValue:@“Title for email” forKey:@"subject"];
[self presentViewController:ActivityView animated:YES completion:nil];
[ActivityView setCompletionHandler:^(NSString *act, BOOL done)
{
NSString *ServiceMsg = nil;
if ( [act isEqualToString:UIActivityTypeMail] )
ServiceMsg = @"Mail sended!";
if ( [act isEqualToString:UIActivityTypePostToTwitter] )
ServiceMsg = @"Post on twitter, ok!";
if ( [act isEqualToString:UIActivityTypePostToFacebook] )
ServiceMsg = @"Post on facebook, ok!";
if ( [act isEqualToString:UIActivityTypeMessage] )
ServiceMsg = @"SMS sended!";
if (done)
{
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:ServiceMsg message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[Alert show];
}
}];
}