///系统分享类型
public enum SystemShareType {
///分享图片
case shareImage(UIImage)
///分享链接
case shareUrl(URL)
///分享带标题链接
case shareTitleUrl(String,URL)
///分享带标题图片链接
case shareTitleImageUrl(String,UIImage,URL)
///分享多张图片最多九张
case shareMoreImages([UIImage])
}
///系统分享
public func XlbSystemShare(_ shareType:SystemShareType){
var arrayItems:[Any] = []
var excludedActivityTypes:[UIActivity.ActivityType] = []
switch shareType {
case let .shareImage(image):
arrayItems.append(image.jpegData(compressionQuality: 1.0) as Any)
excludedActivityTypes = [.message,.mail,.copyToPasteboard,.addToReadingList]
break
case let .shareUrl(url):
arrayItems.append(url)
excludedActivityTypes = [.message,.mail,.addToReadingList,.saveToCameraRoll]
break
case let .shareTitleUrl(title, url):
arrayItems.append(title)
arrayItems.append(url)
excludedActivityTypes = [.message,.mail,.addToReadingList,.saveToCameraRoll]
break
case let .shareTitleImageUrl(title, image, url):
excludedActivityTypes = [.message,.mail,.addToReadingList,.saveToCameraRoll]
arrayItems.append(title)
arrayItems.append(image.jpegData(compressionQuality: 1.0) as Any)
arrayItems.append(url)
break
case let .shareMoreImages(images):
excludedActivityTypes = [.message,.mail,.copyToPasteboard,.addToReadingList,.saveToCameraRoll]
for (index,image) in images.enumerated() {
if images == nil {
continue
}
if index < 9 {
arrayItems.append(image.jpegData(compressionQuality: 1.0) as Any)
} else {
break
}
}
break
}
excludedActivityTypes.append(.assignToContact)
let activityController = UIActivityViewController(activityItems: arrayItems, applicationActivities: nil)
activityController.excludedActivityTypes = excludedActivityTypes
if let window = UIApplication.shared.keyWindow, let rootViewController = window.rootViewController {
activityController.popoverPresentationController?.sourceView = window
activityController.popoverPresentationController?.sourceRect = CGRect(origin: CGPoint(x: window.bounds.width / 2.0, y: window.bounds.size.height - 1.0), size: CGSize(width: 1.0, height: 1.0))
activityController.modalPresentationStyle = .fullScreen
rootViewController.present(activityController, animated: true, completion: nil)
}
}
iOS 系统分享-不同内容
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 在使用系统集成的时候,分享图片到微信或QQ等平台,报错不支持该类型的内容 在分享的时候需要把UIimage格式的图...
- 如需转载请评论或简信,并注明出处,未经允许不得转载 前言 最近在做一个需求,一个html页面需要生成一个二维码图片...
- 调用系统分享方式,分享到Facebook时,点击按钮 无反应... 做开发的时候,我的手机(港版)是正常的;测试版...