mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
保存图片到相册
This commit is contained in:
parent
625ef514fc
commit
4d5d90778d
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import IQKeyboardManagerSwift
|
import IQKeyboardManagerSwift
|
||||||
import IQKeyboardToolbarManager
|
import IQKeyboardToolbarManager
|
||||||
|
import SVProgressHUD
|
||||||
import SwiftyStoreKit
|
import SwiftyStoreKit
|
||||||
import UIKit
|
import UIKit
|
||||||
import UserNotifications
|
import UserNotifications
|
||||||
@ -32,7 +33,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|||||||
|
|
||||||
// 必须在应用一开始就配置,否则应用可能提前在配置之前试用了 Realm() ,则会创建两个独立数据库。
|
// 必须在应用一开始就配置,否则应用可能提前在配置之前试用了 Realm() ,则会创建两个独立数据库。
|
||||||
setupRealm()
|
setupRealm()
|
||||||
|
|
||||||
|
SVProgressHUD.setMinimumDismissTimeInterval(1.5)
|
||||||
|
|
||||||
IQKeyboardManager.shared.isEnabled = true
|
IQKeyboardManager.shared.isEnabled = true
|
||||||
IQKeyboardToolbarManager.shared.isEnabled = true
|
IQKeyboardToolbarManager.shared.isEnabled = true
|
||||||
if #available(iOS 14, *), UIDevice.current.userInterfaceIdiom == .pad {
|
if #available(iOS 14, *), UIDevice.current.userInterfaceIdiom == .pad {
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>NSPhotoLibraryAddUsageDescription</key>
|
||||||
|
<string>Save the image to the photo library</string>
|
||||||
<key>CFBundleURLTypes</key>
|
<key>CFBundleURLTypes</key>
|
||||||
<array>
|
<array>
|
||||||
<dict>
|
<dict>
|
||||||
|
|||||||
@ -2668,6 +2668,35 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"noPermission" : {
|
||||||
|
"extractionState" : "manual",
|
||||||
|
"localizations" : {
|
||||||
|
"en" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "No permission"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ja" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "権限がありません"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tr" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "İzin yok"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "没有权限"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"Notice1" : {
|
"Notice1" : {
|
||||||
"extractionState" : "manual",
|
"extractionState" : "manual",
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
@ -3393,6 +3422,64 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"save" : {
|
||||||
|
"extractionState" : "manual",
|
||||||
|
"localizations" : {
|
||||||
|
"en" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Save"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ja" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "保存"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tr" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Kaydet"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "保存"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"saveSuccess" : {
|
||||||
|
"extractionState" : "manual",
|
||||||
|
"localizations" : {
|
||||||
|
"en" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Saved to your photos!"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ja" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "アルバムに保存したよ!"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tr" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Albüme kaydedildi!"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "已保存到相册!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"SecureConnection" : {
|
"SecureConnection" : {
|
||||||
"extractionState" : "manual",
|
"extractionState" : "manual",
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
|
|||||||
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
import ImageViewer_swift
|
import ImageViewer_swift
|
||||||
import Kingfisher
|
import Kingfisher
|
||||||
|
import Photos
|
||||||
|
import SVProgressHUD
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class MessageItemView: UIView {
|
class MessageItemView: UIView {
|
||||||
@ -168,13 +170,25 @@ extension MessageItemView {
|
|||||||
imageView.isHidden = false
|
imageView.isHidden = false
|
||||||
// loadDiskFileSynchronously
|
// loadDiskFileSynchronously
|
||||||
imageView.kf.setImage(with: URL(string: image), options: [.targetCache(imageCache), .keepCurrentImageWhileLoading, .loadDiskFileSynchronously]) { [weak self] result in
|
imageView.kf.setImage(with: URL(string: image), options: [.targetCache(imageCache), .keepCurrentImageWhileLoading, .loadDiskFileSynchronously]) { [weak self] result in
|
||||||
// 获取系统是否是夜间模式
|
|
||||||
let isDarkMode = UIScreen.main.traitCollection.userInterfaceStyle == .dark
|
|
||||||
self?.imageView.setupImageViewer(options: [.closeIcon(UIImage(named: "back")!), .theme(isDarkMode ? .dark : .light)])
|
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
guard let image = try? result.get().image else {
|
guard let image = try? result.get().image else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取系统是否是夜间模式
|
||||||
|
let isDarkMode = UIScreen.main.traitCollection.userInterfaceStyle == .dark
|
||||||
|
var options: [ImageViewerOption] = [
|
||||||
|
.closeIcon(UIImage(named: "back")!),
|
||||||
|
.theme(isDarkMode ? .dark : .light)
|
||||||
|
]
|
||||||
|
if #available(iOS 14.0, *) {
|
||||||
|
options.append(.rightNavItemTitle(NSLocalizedString("save"), onTap: { _ in
|
||||||
|
// 保存 image 到相册
|
||||||
|
self.saveImageToAlbum(image)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
self.imageView.setupImageViewer(options: options)
|
||||||
|
|
||||||
layoutImageView(image: image)
|
layoutImageView(image: image)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -199,3 +213,28 @@ extension MessageItemView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(iOS 14.0, *)
|
||||||
|
extension MessageItemView {
|
||||||
|
func saveImageToAlbum(_ image: UIImage) {
|
||||||
|
PHPhotoLibrary.requestAuthorization(for: .addOnly) { status in
|
||||||
|
guard status == .authorized || status == .limited else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
SVProgressHUD.showInfo(withStatus: NSLocalizedString("noPermission"))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
PHPhotoLibrary.shared().performChanges({
|
||||||
|
PHAssetChangeRequest.creationRequestForAsset(from: image)
|
||||||
|
}) { success, error in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if success {
|
||||||
|
SVProgressHUD.showSuccess(withStatus: NSLocalizedString("saveSuccess"))
|
||||||
|
} else {
|
||||||
|
SVProgressHUD.showError(withStatus: error?.localizedDescription)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user