1:在UIActivityViewController 里面实现系统自带复制到粘贴板。
NSArray *activities = (@[act1,act2,act3,act4,act5]);
NSString *textToShare = entity.sharedUrl.url;
NSArray *activityItems = @[textToShare];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:activities];
activityController.excludedActivityTypes = (@[
UIActivityTypeAssignToContact,
UIActivityTypeMail,
UIActivityTypeMessage,
UIActivityTypePrint,
UIActivityTypeSaveToCameraRoll,
UIActivityTypePostToFacebook,
UIActivityTypeAirDrop
]);
//给activityVC的属性completionHandler写一个block。
//用以UIActivityViewController执行结束后,被调用,做一些后续处理。
UIActivityViewControllerCompletionHandler myBlock = ^(NSString *activityType,BOOL completed)
{
NSLog(@"activityType :%@", activityType);
if ([activityType isEqualToString:UIActivityTypeCopyToPasteboard]) {
if (completed)
{
[SVProgressHUD showSuccessWithStatus:@"已粘贴到剪贴板"];
}
else
{
NSLog(@"cancel");
}
}
};
// 初始化completionHandler,当post结束之后(无论是done还是cancell)该blog都会被调用
activityController.completionHandler = myBlock;
[self presentViewController:activityController animated:YES completion:NULL];
2: UIButton 实现点击后复制到粘贴板
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = self.shareEntity.sharedUrl.url;
[SVProgressHUD showSuccessWithStatus:@"已粘贴到剪贴板" duration:2.0f];
网友评论