使用UIActivityViewController
集成系统分享功能
/**
分享
@param title 标题
@param image 图标
@param url 链接
@param target r视图控制器
@param complete 回调
*/
+ (void)shareWithTitle:(NSString *)title image:(UIImage *)image url:(NSString *)url target:(UIViewController *)target complete:(void (^)(BOOL isSuccess, UIActivityType type))complete
{
// 分享内容
NSString *shareTitle = title;
UIImage *shareImage = image;
NSURL *shareUrl = [NSURL URLWithString:url];
NSArray *activityItemsArray = @[shareTitle, shareImage, shareUrl];
//
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItemsArray applicationActivities:nil];
activityVC.modalInPopover = YES;
// 禁用分享渠道
// activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo, UIActivityTypeAirDrop, UIActivityTypeOpenInIBooks];
//
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
if (complete) {
complete(completed, activityType);
}
};
//
[target presentViewController:activityVC animated:YES completion:nil];
}
注意
Info.plist
设置属性Localized resources can be mixed
值为YES,以使取消按钮为中文显示。
网友评论