美文网首页
iOS系统分享

iOS系统分享

作者: CN_HarrySun | 来源:发表于2018-04-24 11:28 被阅读22次

利用系统分享分享图片并带有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)
    }

相关文章

网友评论

      本文标题:iOS系统分享

      本文链接:https://www.haomeiwen.com/subject/bzgdlftx.html