Commit 3fef7ab7 authored by Alex朱枝文's avatar Alex朱枝文

微信分享增加缩略图

parent 81644dd7
......@@ -1186,6 +1186,7 @@
0487C1DE2E8BCCA900CE6472 /* YHResourceDetailBaseInfoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0487C1DD2E8BCCA900CE6472 /* YHResourceDetailBaseInfoCell.swift */; };
0487C1E02E8BCCDD00CE6472 /* YHResourceDetailDemandCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0487C1DF2E8BCCDD00CE6472 /* YHResourceDetailDemandCell.swift */; };
0487C1E22E8BCD0200CE6472 /* YHResourceDetailDocumentsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0487C1E12E8BCD0200CE6472 /* YHResourceDetailDocumentsCell.swift */; };
0487C1FD2E99F8E800CE6472 /* YHKingfisherUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0487C1FC2E99F8E800CE6472 /* YHKingfisherUtils.swift */; };
048D6ADB2D5E00DE00BC6F4C /* YHMemberCenterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048D6ADA2D5E00DE00BC6F4C /* YHMemberCenterViewController.swift */; };
048D6ADD2D5EF0A900BC6F4C /* YHMemberCenterHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048D6ADC2D5EF0A900BC6F4C /* YHMemberCenterHeaderView.swift */; };
048D6ADF2D5F0FBE00BC6F4C /* YHMemberCenterHeaderBannerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048D6ADE2D5F0FBE00BC6F4C /* YHMemberCenterHeaderBannerCell.swift */; };
......@@ -2565,6 +2566,7 @@
0487C1DD2E8BCCA900CE6472 /* YHResourceDetailBaseInfoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHResourceDetailBaseInfoCell.swift; sourceTree = "<group>"; };
0487C1DF2E8BCCDD00CE6472 /* YHResourceDetailDemandCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHResourceDetailDemandCell.swift; sourceTree = "<group>"; };
0487C1E12E8BCD0200CE6472 /* YHResourceDetailDocumentsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHResourceDetailDocumentsCell.swift; sourceTree = "<group>"; };
0487C1FC2E99F8E800CE6472 /* YHKingfisherUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHKingfisherUtils.swift; sourceTree = "<group>"; };
048D6ADA2D5E00DE00BC6F4C /* YHMemberCenterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHMemberCenterViewController.swift; sourceTree = "<group>"; };
048D6ADC2D5EF0A900BC6F4C /* YHMemberCenterHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHMemberCenterHeaderView.swift; sourceTree = "<group>"; };
048D6ADE2D5F0FBE00BC6F4C /* YHMemberCenterHeaderBannerCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHMemberCenterHeaderBannerCell.swift; sourceTree = "<group>"; };
......@@ -6298,6 +6300,7 @@
045C0F2C2D12CA5E00BD2DC0 /* YHHUD */,
045C0F2D2D12CA5E00BD2DC0 /* AlignedCollectionViewFlowLayout.swift */,
045C0F2E2D12CA5E00BD2DC0 /* YhCacheTool.swift */,
0487C1FC2E99F8E800CE6472 /* YHKingfisherUtils.swift */,
045C0F2F2D12CA5E00BD2DC0 /* YhConstant.swift */,
045C0F302D12CA5E00BD2DC0 /* YHConstantArrayData.swift */,
045C0F312D12CA5E00BD2DC0 /* YhOverlayView.swift */,
......@@ -8743,6 +8746,7 @@
045C13372D12CA5F00BD2DC0 /* YHResignFamilyInfoListCell.swift in Sources */,
045C13382D12CA5F00BD2DC0 /* YHButlerMessageReportHandler.swift in Sources */,
045C13392D12CA5F00BD2DC0 /* YHAdopterMainModel.swift in Sources */,
0487C1FD2E99F8E800CE6472 /* YHKingfisherUtils.swift in Sources */,
045C133A2D12CA5F00BD2DC0 /* YHInvitationWithGiftsFirstTableViewCell.swift in Sources */,
045C133B2D12CA5F00BD2DC0 /* YHUploadCertificateDetailVC.swift in Sources */,
045C133C2D12CA5F00BD2DC0 /* YHResignMaterialCell.swift in Sources */,
......
......@@ -415,7 +415,7 @@ private extension YHH5WebViewVC {
gk_navItemRightSpace = 16
}
@objc func share() {
@objc func share(_ shareImageUrl: String? = nil) {
if self.isShareToMiniProgramFlag {
if let path = self.shareMiniPath, !path.isEmpty {
......@@ -436,7 +436,17 @@ private extension YHH5WebViewVC {
if !shareUrl.isEmpty &&
!self.shareH5Title.isEmpty &&
!self.shareH5Describe.isEmpty {
YHShareManager.shared.sendLinkContent(self.shareH5Title, self.shareH5Describe, UIImage(named: "shareIcon") ?? UIImage(), link: shareUrl)
if let shareImageUrl = shareImageUrl, !shareImageUrl.isEmpty {
YHHUD.show(.progress(message: ""))
YHKingfisherUtils.fetchImage(with: shareImageUrl) { image in
YHHUD.hide()
DispatchQueue.main.async {
YHShareManager.shared.sendLinkContent(self.shareH5Title, self.shareH5Describe, image ?? UIImage(named: "shareIcon") ?? UIImage(), link: shareUrl)
}
}
} else {
YHShareManager.shared.sendLinkContent(self.shareH5Title, self.shareH5Describe, UIImage(named: "shareIcon") ?? UIImage(), link: shareUrl)
}
}
}
}
......@@ -686,11 +696,11 @@ extension YHH5WebViewVC {
}
// 17、H5调用 App的分享
func shareH5Syn(title: String, desc: String, url: String) {
func shareH5Syn(title: String, desc: String, url: String, shareImageUrl: String? = nil) {
shareUrlFromOutside = url
shareH5Title = title
shareH5Describe = desc
share()
share(shareImageUrl)
}
// 登录带token刷新
......
......@@ -230,16 +230,18 @@ extension YHJsApi {
ShareH5Title : "分享标题"
ShareH5Describe : "分享描述"
ShareH5Url : "分享链接"
ShareImgUrl: "图片链接"
}
*/
if !jsonObject.isEmpty {
let shareH5Title: String = jsonObject["ShareH5Title"] as? String ?? ""
let shareH5Describe: String = jsonObject["ShareH5Describe"] as? String ?? ""
let shareH5Url: String = jsonObject["ShareH5Url"] as? String ?? ""
let shareImageUrl: String? = jsonObject["ShareImgUrl"] as? String
if !shareH5Title.isEmpty, !shareH5Describe.isEmpty, !shareH5Url.isEmpty {
if let delegate = self.delegate as? YHH5WebViewVC {
delegate.shareH5Syn(title: shareH5Title, desc: shareH5Describe, url: shareH5Url)
delegate.shareH5Syn(title: shareH5Title, desc: shareH5Describe, url: shareH5Url, shareImageUrl: shareImageUrl)
}
} else {
printLog("参数不合法...")
......
//
// YHKingfisherUtils.swift
// galaxy
//
// Created by alexzzw on 2025/10/11.
// Copyright © 2025 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import Kingfisher
class YHKingfisherUtils: NSObject {
static func fetchImage(with urlString: String?,
completion: @escaping (UIImage?) -> Void) {
guard let urlString = urlString, let url = URL(string: urlString) else {
completion(nil)
return
}
let key = url.absoluteString
// 检查缓存
if ImageCache.default.isCached(forKey: key) {
ImageCache.default.retrieveImage(forKey: key) { result in
switch result {
case .success(let cacheResult):
if let image = cacheResult.image {
// 缓存命中且图片有效
completion(image)
} else {
// 缓存命中但图片为空,降级到下载
downloadAndCacheImage(url: url, key: key, completion: completion)
}
case .failure:
// 缓存读取失败,降级到下载
downloadAndCacheImage(url: url, key: key, completion: completion)
}
}
} else {
// 缓存未命中,直接下载
downloadAndCacheImage(url: url, key: key, completion: completion)
}
}
// 辅助方法:下载并缓存图片
private static func downloadAndCacheImage(url: URL,
key: String,
completion: @escaping (UIImage?) -> Void) {
ImageDownloader.default.downloadImage(with: url, options: nil) { result in
switch result {
case .success(let imageLoadingResult):
let image = imageLoadingResult.image
ImageCache.default.store(image, forKey: key)
completion(image)
case .failure:
completion(nil)
}
}
}
@available(iOS 13.0, *)
static func fetchImage(with urlString: String?) async -> UIImage? {
guard let urlString = urlString, let url = URL(string: urlString) else {
return nil
}
let key = url.absoluteString
return await withCheckedContinuation { continuation in
if ImageCache.default.isCached(forKey: key) {
ImageCache.default.retrieveImage(forKey: key) { result in
switch result {
case .success(let cacheResult):
if let image = cacheResult.image {
// 缓存命中且成功获取
continuation.resume(returning: image)
} else {
// 缓存命中但图片为空,降级到下载
self.downloadAndCacheImage(url: url, key: key, continuation: continuation)
}
case .failure:
// 缓存读取失败,降级到下载
self.downloadAndCacheImage(url: url, key: key, continuation: continuation)
}
}
} else {
// 缓存未命中,直接下载
downloadAndCacheImage(url: url, key: key, continuation: continuation)
}
}
}
// 辅助方法:下载并缓存图片
private static func downloadAndCacheImage(
url: URL,
key: String,
continuation: CheckedContinuation<UIImage?, Never>
) {
ImageDownloader.default.downloadImage(with: url, options: nil) { result in
switch result {
case .success(let imageLoadingResult):
let image = imageLoadingResult.image
ImageCache.default.store(image, forKey: key)
continuation.resume(returning: image)
case .failure:
continuation.resume(returning: nil)
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment