本文介绍了如何知道在调用activityController setCompletionHandler之前在UIActivityViewController中单击了哪个图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何知道在调用activityController setCompletionHandler:^(NSString *activityType, BOOL completed)
之前在UIActivityViewController
中单击了哪个图标?
How to know which icon is clicked in UIActivityViewController
before activityController setCompletionHandler:^(NSString *activityType, BOOL completed)
is called ?
我想共享不同的文本以便与Twitter和Facebook共享.
I want to share different text for sharing with twitter and facebook.
-(IBAction)btnSharePressedFromOffersDetail:(id)sender
{
NSString *posturl= @"facebook or twitter";
UISimpleTextPrintFormatter *printData = [[UISimpleTextPrintFormatter alloc]init];
NSArray *Itemsarray=@[posturl,printData];
UIActivityViewController *activityController = [[UIActivityViewController alloc]initWithActivityItems:Itemsarray applicationActivities:nil];
[self presentViewController:activityController
animated:YES completion:nil];
[activityController setCompletionHandler:^(NSString *activityType, BOOL completed)
{
NSLog(@"Activity = %@",activityType);
NSLog(@"Completed Status = %d",completed);
if (completed)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:@"Thanks for sharing!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
}
}];
}
推荐答案
如果您的目标是对Twitter或Facebook使用不同的文本,则实现UIActivityItemSource协议的是共享模型的责任.
If your goal is to use a different text for Twitter or Facebook, it's the responsability of your shared Model who implement the UIActivityItemSource protocol.
- (id) activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
if([activityType isEqualToString:UIActivityTypePostToFacebook]) return @"Facebook text";
else if([activityType UIActivityTypePostToTwitter]) return @"Twitter text";
else return @"Default text";
}
这篇关于如何知道在调用activityController setCompletionHandler之前在UIActivityViewController中单击了哪个图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!