利用系統(tǒng)分享分享圖片并帶有hashTag
// 系統(tǒng)分享
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的話糯俗,成功回調(diào)直接返回
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)
}