Commit 7f297b2a authored by pete谢兆麟's avatar pete谢兆麟

H5 交互方法

parent 0f3a4b28
...@@ -144,8 +144,19 @@ class YHHomeHoldViewPageViewController: YHBaseViewController { ...@@ -144,8 +144,19 @@ class YHHomeHoldViewPageViewController: YHBaseViewController {
checkHomeAlertView() checkHomeAlertView()
getCurrentUserInfo() getCurrentUserInfo()
getConfigData() getConfigData()
NotificationCenter.default.addObserver(self, selector: #selector(handleNotification(_:)), name: YhConstant.YhNotification.backToHomeNotification, object: nil)
} }
@objc func handleNotification(_ notification: Notification) {
if let userInfo = notification.userInfo, let value = userInfo["value"] as? Int {
segmentedView.selectItemAt(index: value)
}
}
deinit {
// 移除观察者
NotificationCenter.default.removeObserver(self)
}
private func isViewVisibleOnScreen(view: UIView) -> Bool { private func isViewVisibleOnScreen(view: UIView) -> Bool {
let viewFrame = view.convert(view.bounds, to: UIScreen.main.coordinateSpace) let viewFrame = view.convert(view.bounds, to: UIScreen.main.coordinateSpace)
......
...@@ -661,6 +661,23 @@ extension YHH5WebViewVC { ...@@ -661,6 +661,23 @@ extension YHH5WebViewVC {
} }
} }
func savePicToLocal(_ data: String) {
func saveBase64ImageToPhotoLibrary(base64String: String) {
// 解码 Base64 字符串为 Data
guard let imageData = Data(base64Encoded: base64String) else {
printLog("无法解码 Base64 字符串")
return
}
// 创建 UIImage
guard let image = UIImage(data: imageData) else {
printLog("无法创建 UIImage")
return
}
self.saveImage(image)
}
}
func saveImage(_ image: UIImage) { func saveImage(_ image: UIImage) {
// 确保应用有权访问相册 // 确保应用有权访问相册
PHPhotoLibrary.requestAuthorization { status in PHPhotoLibrary.requestAuthorization { status in
......
...@@ -535,4 +535,23 @@ extension YHJsApi { ...@@ -535,4 +535,23 @@ extension YHJsApi {
} }
} }
} }
//1.保存base64图片格式到本地
@objc func savePicToLocal(_ data: String) {
DispatchQueue.main.async {
if let delegate = self.delegate as? YHH5WebViewVC {
delegate.savePicToLocal(data)
}
}
}
//1.保存base64图片格式到本地
@objc func backToHomeIndex(_ index: Int) {
DispatchQueue.main.async {
UIViewController.current?.navigationController?.popToRootViewController(animated: true)
UIViewController.current?.tabBarController?.selectedIndex = 0
NotificationCenter.default.post(name: YhConstant.YhNotification.backToHomeNotification, object: nil, userInfo: ["value": index])
}
}
} }
...@@ -320,5 +320,7 @@ extension YhConstant { ...@@ -320,5 +320,7 @@ extension YhConstant {
// 已经展示银河管家 // 已经展示银河管家
public static let didLoadYhManagerNotification = Notification.Name(rawValue: "com.yinhe.didLoadYhManager") public static let didLoadYhManagerNotification = Notification.Name(rawValue: "com.yinhe.didLoadYhManager")
public static let backToHomeNotification = Notification.Name(rawValue: "com.yinhe.backToHomeNotification")
} }
} }
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