利用系统分享分享图片并带有hashTag
// 系统分享
fileprivate func systemShare(image: UIImage, hashTag: String?, fromController: UIViewController) {
let activityVC = UIActivityViewController(activityItems: [image], applicationActivities: nil)
activityVC.completionWithItemsHandler = { activityType, completed, returnedItems, activityError in
if completed {
// 如果是copy的话,成功回调直接返回
if activityType == .copyToPasteboard { return }
// 分享成功后弹窗提示返回
let dialog = PopupDialogUtil.sheetWith(title: NSLocalizedString("Thank you for sharing!", comment: ""), message: nil, image: R.image.guide_praise_top(), preferredButtonTitle: NSLocalizedString("ok", comment: ""),preferredButtonBlock: {
// 返回到根视图控制器
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate,
let rootNavigationController = appDelegate.rootNavigationController
else {
return
}
rootNavigationController.popToRootViewController(animated: true)
})
fromController.present(dialog, animated: true, completion: nil)
} else {
if activityError != nil {
// 分享失败
ProgressHUD.showTextHUD(withText: NSLocalizedString("share failed", comment: ""), in: fromController.view, afterDelay: 1)
} else {
// 分享取消
ProgressHUD.showTextHUD(withText: NSLocalizedString("share canceled", comment: ""), in: fromController.view, afterDelay: 1)
}
}
}
activityVC.excludedActivityTypes = [.airDrop, .addToReadingList, .saveToCameraRoll, .print, .assignToContact] // 去掉airdrop等
fromController.present(activityVC, animated: true, completion: nil)
}
网友评论