Commit f83b3045 authored by yqz's avatar yqz

私密相册

parent a4554cf5
......@@ -223,7 +223,9 @@
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6K23946NQ5;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = PhoneManager/Info.plist;
INFOPLIST_KEY_NSCameraUsageDescription = "We need camera access to access image storage information";
INFOPLIST_KEY_NSLocalNetworkUsageDescription = "We need to access the network to load content";
INFOPLIST_KEY_NSMicrophoneUsageDescription = "We need microphone permission to record videos";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "We need album permission to access image storage information";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
......@@ -263,7 +265,9 @@
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6K23946NQ5;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = PhoneManager/Info.plist;
INFOPLIST_KEY_NSCameraUsageDescription = "We need camera access to access image storage information";
INFOPLIST_KEY_NSLocalNetworkUsageDescription = "We need to access the network to load content";
INFOPLIST_KEY_NSMicrophoneUsageDescription = "We need microphone permission to record videos";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "We need album permission to access image storage information";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
......
......@@ -10,7 +10,7 @@ import AppIntents
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
//test
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
......@@ -28,7 +28,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
window?.makeKeyAndVisible()
}
return true
}
......
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_add_secret.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_add_secret@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_add_secret@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_lock_secret.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_lock_secret@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_lock_secret@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_photo_secret.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_photo_secret@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_photo_secret@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_unlock_secret.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_unlock_secret@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_unlock_secret@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_video_secret.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_video_secret@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_video_secret@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "img_file_defpage.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_file_defpage@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_file_defpage@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "img_secret_pop.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_secret_pop@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_secret_pop@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -52,7 +52,15 @@ class HomeViewController:BaseViewController {
self.navigationController?.pushViewController(vc, animated: true)
}
break
case 1:
DispatchQueue.main.async { [weak self] in
guard let self else {return}
let vc:SecretViewController = SecretViewController()
self.navigationController?.pushViewController(vc, animated: true)
}
break
default:
break
}
......
//
// SecretSetViewController.swift
// PhoneManager
//
// Created by edy on 2025/3/31.
//
import UIKit
class SecretSetViewController: BaseViewController, UITextFieldDelegate {
enum SecretType {
case create
case verify
}
var Callback:((_ suc:Bool)->Void)?
var secretType:SecretType = .create {
didSet{
if secretType == .create {
setTitle.text = "Create New PlN"
}else{
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
titleView.model.title = "Secret Library"
titleView.titleLabel.textColor = .black
titleView.titleLabel.textAlignment = .left
setUI()
ps.becomeFirstResponder()
collect.register(SecretSetPsCell.self, forCellWithReuseIdentifier: SecretSetPsCellID)
}
private var Secret = "" {
didSet {
collect.reloadData()
if Secret.count == 4 {
UserDefaults.standard.set(Secret, forKey: SecretViewController.psKey)
guard Callback != nil else {
return
}
Callback!(true)
self.navigationController?.popViewController(animated: true)
}
}
}
private func setUI() -> Void {
view.addSubview(setInfo)
view.addSubview(setTitle)
view.addSubview(collect)
setInfo.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview().offset(62)
}
setTitle.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(setInfo.snp.bottom).offset(16)
}
collect.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.width.equalTo(20*4.0 + 3 * 20.0 )
make.top.equalTo(setTitle.snp.bottom).offset(32);
make.height.equalTo(20)
}
}
private lazy var collect: UICollectionView = {
let flowLayout = UICollectionViewFlowLayout()
let col = UICollectionView(frame: CGRectZero, collectionViewLayout: flowLayout)
col.delegate = self;
col.dataSource = self;
return col
}()
private lazy var ps: UITextField = {
let tf = UITextField()
tf.alpha = 0
tf.delegate = self;
tf.keyboardType = .numberPad
view.addSubview(tf)
return tf
}()
private lazy var setInfo:UIImageView = {
let info = UIImageView(image: UIImage(named: "img_secret_pop"))
info.contentMode = .scaleToFill
return info
}()
private lazy var setTitle: UILabel = {
let st = UILabel()
st.text = "Create New PlN"
st.font = UIFont.boldSystemFont(ofSize: 20)
st.textColor = .black
st.textAlignment = .center
return st
}()
}
extension SecretSetViewController:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell:SecretSetPsCell = collectionView.dequeueReusableCell(withReuseIdentifier: SecretSetPsCellID, for: indexPath) as! SecretSetPsCell
cell.isSelect = Secret.count > indexPath.row;
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 20
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSizeMake(20, 20)
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
var st:NSString = textField.text as? NSString ?? ""
st = st.replacingCharacters(in: range, with: string) as NSString
if st.length > 4 {
Secret = st.substring(to: 4)
return false
}
Secret = st as String;
return true
}
}
This diff is collapsed.
//
// SecretActionView.swift
// PhoneManager
//
// Created by edy on 2025/3/31.
//
import UIKit
class SecretActionView: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .colorWithHex(hexStr: "#000000", alpha: 0.5)
setUI()
}
private func setUI() -> Void {
view.addSubview(backView)
backView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.bottom.equalTo(view.snp.bottom)
}
lineV.snp.makeConstraints { make in
make.top.equalToSuperview().offset(16)
make.centerX.equalToSuperview()
make.size.equalTo(CGSize(width: 57.RW(), height: 4))
}
descpLabel.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(lineV.snp.bottom).offset(20)
}
CarmaBtn.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(15)
make.top.equalTo(descpLabel.snp.bottom).offset(16)
make.height.equalTo(56)
}
PhotoBtn.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(15)
make.top.equalTo(CarmaBtn.snp.bottom).offset(16)
make.height.equalTo(56)
}
cancelBtn.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(15)
make.top.equalTo(PhotoBtn.snp.bottom).offset(16)
make.height.equalTo(56)
make.bottom.equalToSuperview().offset(-46.RH())
}
view.layoutIfNeeded()
backView.cornerCut(radius: 20, corner: [.topLeft,.topRight])
}
var callback:((_ idx:Int)->Void)?
@objc private func actionTouch(_ sender:UIButton) -> Void {
self.dismiss(animated: true)
guard callback != nil else {
return
}
callback!(sender.tag % 0x10)
}
func show() -> Void {
guard let rt = cWindow?.rootViewController else { return }
self.modalTransitionStyle = .crossDissolve
self.modalPresentationStyle = .overFullScreen
rt.present(self, animated: true)
}
private lazy var backView: UIView = {
let back = UIView()
back.backgroundColor = .white
return back
}()
private lazy var lineV: UIView = {
let l = UIView()
l.backgroundColor = .colorWithHex(hexStr: "#D9D9D9")
l.layer.cornerRadius = 4
backView.addSubview(l)
return l
}()
private lazy var descpLabel: UILabel = {
let desc = UILabel()
desc.text = "Choose Action"
desc.textColor = .colorWithHex(hexStr: "#B3B3B3")
desc.textAlignment = .center
desc.font = UIFont.systemFont(ofSize: 14)
backView.addSubview(desc)
return desc
}()
private lazy var CarmaBtn: UIButton = {
let carma = UIButton(type: .custom)
carma.setImage(UIImage(named: "ic_video_secret"), for: .normal)
carma.backgroundColor = .colorWithHex(hexStr: "#F2F6FC")
carma.titleLabel?.font = UIFont.systemFont(ofSize: 16)
carma.contentHorizontalAlignment = .leading
carma.layer.cornerRadius = 12
carma.tag = 0x10;
carma.setTitle("Instantly Detect Similar Photos", for: .normal)
carma.setTitleColor(.black, for: .normal)
carma.addTarget(self, action: #selector(actionTouch(_:)), for: .touchUpInside)
carma.imageEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
carma.titleEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 0)
backView.addSubview(carma)
return carma
}()
private lazy var PhotoBtn: UIButton = {
let Photo = UIButton(type: .custom)
Photo.setImage(UIImage(named: "ic_photo_secret"), for: .normal)
Photo.backgroundColor = .colorWithHex(hexStr: "#F2F6FC")
Photo.titleLabel?.font = UIFont.systemFont(ofSize: 16)
Photo.contentHorizontalAlignment = .leading
Photo.layer.cornerRadius = 12
Photo.tag = 0x11;
Photo.setTitle("No Ads and Limits", for: .normal)
Photo.setTitleColor(.black, for: .normal)
Photo.addTarget(self, action: #selector(actionTouch(_:)), for: .touchUpInside)
Photo.imageEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
Photo.titleEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 0)
backView.addSubview(Photo)
return Photo
}()
lazy var cancelBtn: UIButton = {
let can = UIButton(type: .custom)
can.setTitle("Oldest", for: .normal)
can.backgroundColor = .white
can.tag = 0x12
can.addTarget(self, action: #selector(actionTouch(_:)), for: .touchUpInside)
can.setTitleColor(.black, for: .normal)
backView.addSubview(can)
return can
}()
deinit {
callback = nil
}
}
//
// SecretAlert.swift
// PhoneManager
//
// Created by edy on 2025/3/31.
//
import UIKit
class SecretAlert: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .colorWithHex(hexStr: "#000000", alpha: 0.7)
setUI()
}
var callback:((_ idx:Int)->Void)?
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.modalTransitionStyle = .crossDissolve
self.modalPresentationStyle = .overFullScreen
}
private func setUI() -> Void {
view.addSubview(showView)
showView.addSubview(showInfo)
showView.addSubview(showTitle)
showView.addSubview(showDesc)
showView.addSubview(createPin)
showView.addSubview(maybe)
showView.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(15)
make.centerY.equalToSuperview()
}
showInfo.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview().offset(32)
}
showTitle.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(showInfo.snp.bottom).offset(16)
make.left.right.equalToSuperview().inset(35)
}
showDesc.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(20)
make.top.equalTo(showTitle.snp.bottom).offset(8)
make.centerX.equalToSuperview()
}
createPin.snp.makeConstraints { make in
make.top.equalTo(showDesc.snp.bottom).offset(16)
make.left.right.equalToSuperview().inset(20)
make.height.equalTo(46)
}
maybe.snp.makeConstraints { make in
make.top.equalTo(createPin.snp.bottom).offset(16)
make.left.right.equalTo(createPin)
make.height.equalTo(46)
make.bottom.equalToSuperview().offset(-20)
}
}
func show() -> Void {
guard let root = cWindow?.rootViewController else { return }
self.modalPresentationStyle = .overFullScreen
self.modalTransitionStyle = .crossDissolve
root.present(self, animated: true)
}
@objc func creatPinTouch() -> Void {
guard (callback != nil) else { return }
callback!(1)
}
@objc func maybeTouch() -> Void {
guard (callback != nil) else { return }
callback!(0)
}
private lazy var createPin: UIButton = {
let btn = UIButton(type: .custom)
btn.backgroundColor = .colorWithHex(hexStr: "#0082FF")
btn.setTitle("Create PlN", for: .normal)
btn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
btn.layer.cornerRadius = 46/2.0
btn.clipsToBounds = true
btn.setTitleColor(.white, for: .normal)
btn.addTarget(self, action: #selector(creatPinTouch), for: .touchUpInside)
return btn
}()
private lazy var maybe: UIButton = {
let btn = UIButton(type: .custom)
btn.backgroundColor = .white
btn.setTitle("Maybe Later", for: .normal)
btn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
btn.setTitleColor(.colorWithHex(hexStr: "#666666"), for: .normal)
btn.addTarget(self, action: #selector(maybeTouch), for: .touchUpInside)
return btn
}()
private lazy var showView: UIView = {
let v = UIView()
v.backgroundColor = .white
v.layer.cornerRadius = 12;
v.clipsToBounds = true
return v
}()
private lazy var showInfo : UIImageView = {
let info = UIImageView(image: UIImage(named: "img_secret_pop"))
info.contentMode = .scaleToFill
return info
}()
private lazy var showTitle: UILabel = {
let l = UILabel()
l.font = UIFont.boldSystemFont(ofSize: 20)
l.text = "This is your Secret Library!"
l.textAlignment = .center
l.textColor = .colorWithHex(hexStr: "#1A1A1A")
return l
}()
private lazy var showDesc: UILabel = {
let d = UILabel()
d.text = "Protect your private photos and videos by creating PIN."
d.textColor = .colorWithHex(hexStr: "#666666")
d.numberOfLines = 0
d.font = UIFont.systemFont(ofSize: 14)
d.textAlignment = .center
d.numberOfLines = 0
return d
}()
}
//
// SecretBottomView.swift
// PhoneManager
//
// Created by edy on 2025/3/31.
//
import UIKit
class SecretBottomView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(but)
but.snp.makeConstraints { make in
make.height.equalTo(46)
make.top.left.right.equalToSuperview().inset(15)
}
layer.insertSublayer(clayer, at: 0)
}
override func layoutSubviews() {
super.layoutSubviews()
clayer.frame = self.bounds
layer.shadowColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 0.1).cgColor
layer.shadowOffset = CGSize(width: 0, height: -2)
layer.shadowOpacity = 1
layer.shadowRadius = 10
}
private lazy var clayer: CALayer = {
let l = CALayer()
l.backgroundColor = UIColor.white.cgColor
return l
}()
var callback:(()->Void)?
@objc func AddNew() -> Void {
guard (callback != nil) else {return}
callback!()
}
private lazy var but: UIButton = {
let b = UIButton(type: .custom)
b.backgroundColor = .colorWithHex(hexStr: "#0082FF")
b.layer.cornerRadius = 46/2.0
b.clipsToBounds = true
b.setTitle("Add New", for: .normal)
b.setImage(UIImage(named: "ic_add_secret"), for: .normal)
b.addTarget(self, action: #selector(AddNew), for: .touchUpInside)
return b
}()
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
//
// SecretFirstCell.swift
// PhoneManager
//
// Created by edy on 2025/3/31.
//
import UIKit
let SecretFirstCellID = "SecretFirstCell"
class SecretFirstCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
setUI()
backgroundColor = UIColor.random
}
private func setUI() -> Void {
isSelect = false
infoView.snp.makeConstraints { make in
make.left.right.bottom.top.equalToSuperview()
}
selectInfo.snp.makeConstraints { make in
make.right.bottom.equalToSuperview().inset(12)
make.size.equalTo(CGSize(width: 24, height: 24))
}
timeLabe.snp.makeConstraints { make in
make.left.bottom.equalToSuperview().inset(14)
}
}
var isSelect:Bool = false {
didSet{
selectInfo.isSelected = isSelect
}
}
var imageText:String = "" {
didSet {
if imageText.count > 0 {
imageText.loadPhotoOrVideo {[weak self] duration, icon in
self?.infoView.image = icon
self?.timeLabe.text = self?.timeStringformatter(Int(duration))
}
bringSubviewToFront(selectInfo)
}
}
}
private func timeStringformatter(_ time:Int) -> String {
if time > 0 {
let hour = time / 3600
let minte = (time / 3600) / 60
let sec = (time % 60)
return String(format: "%02d:%02d:%02d", hour,minte,sec)
}
return ""
}
private lazy var selectInfo: UIButton = {
let info = UIButton(type: .custom)
info.setImage(UIImage(named: "home_info_norl"), for: .normal)
info.setImage(UIImage(named: "home_info_seleted"), for: .selected)
info.isUserInteractionEnabled = false
addSubview(info)
return info
}()
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private lazy var infoView: UIImageView = {
let info = UIImageView()
info.contentMode = .scaleAspectFill
addSubview(info)
return info
}()
lazy var timeLabe: UILabel = {
let l = UILabel()
l.textColor = .white
l.font = UIFont.systemFont(ofSize: 14)
addSubview(l)
return l
}()
}
//
// SecretNotDataView.swift
// PhoneManager
//
// Created by edy on 2025/3/31.
//
import UIKit
class SecretNotDataView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(info)
addSubview(NotDataTitle)
addSubview(NotdataDesc)
info.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview().offset(-20.RH())
}
NotDataTitle.snp.makeConstraints { make in
make.top.equalTo(info.snp.bottom).offset(24.RH())
make.centerX.equalToSuperview()
}
NotdataDesc.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(30.RH())
make.top.equalTo(NotDataTitle.snp.bottom).offset(8)
}
}
private lazy var NotDataTitle: UILabel = {
let l = UILabel()
l.text = "No Secret Files"
l.textColor = .colorWithHex(hexStr: "#333333")
l.font = UIFont.boldSystemFont(ofSize: 24)
l.textAlignment = .center
return l
}()
private lazy var info: UIImageView = {
let info = UIImageView(image: UIImage(named: "img_file_defpage"))
info.contentMode = .scaleToFill
return info
}()
private lazy var NotdataDesc: UILabel = {
let desc = UILabel()
desc.text = "Tap to \"Add New\" button to add secret photos and videos"
desc.textColor = .colorWithHex(hexStr: "#666666")
desc.font = UIFont.systemFont(ofSize: 14)
desc.numberOfLines = 0
desc.textAlignment = .center
return desc
}()
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
//
// SecretSetPsCell.swift
// PhoneManager
//
// Created by edy on 2025/3/31.
//
import UIKit
let SecretSetPsCellID = "SecretSetPsCell"
class SecretSetPsCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
isSelect = false;
self.layer.cornerRadius = 8
self.clipsToBounds = true
}
var isSelect:Bool = false {
didSet{
if isSelect {
self.backgroundColor = UIColor.colorWithHex(hexStr: "#0082FF")
}else{
self.backgroundColor = .white
self.layer.borderColor = UIColor.colorWithHex(hexStr: "#0082FF").cgColor
self.layer.borderWidth = 1
}
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
//
// NSString+Ex.h
// PhoneManager
//
// Created by edy on 2025/4/1.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSString (Ex)
- (NSArray<NSString *> *)contentOfDir;
@end
NS_ASSUME_NONNULL_END
//
// NSString+Ex.m
// PhoneManager
//
// Created by edy on 2025/4/1.
//
#import "NSString+Ex.h"
@implementation NSString (Ex)
- (NSArray *)contentOfDir
{
NSString *fils = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
fils = [fils stringByAppendingPathComponent:self];
id files = [NSFileManager.defaultManager contentsOfDirectoryAtPath:fils error:nil];
return files;
}
@end
......@@ -3,3 +3,4 @@
//
#import "OpenCVWrapper.h"
#import "NSString+Ex.h"
......@@ -10,7 +10,7 @@ import Photos
import UIKit
import Vision
import CoreML
import HXPhotoPicker
enum SoureceType {
case Photo
......@@ -621,3 +621,68 @@ class PhotoAndVideoMananger {
}
}
class SecretPhotoManager: NSObject, PhotoPickerControllerDelegate , CameraControllerDelegate {
func cameraController(_ cameraController: HXPhotoPicker.CameraController, didFinishWithResult result: HXPhotoPicker.CameraController.Result, phAsset: PHAsset?, location: CLLocation?) {
switch result {
case .image(let image):
let data = image.pngData()
guard callback != nil else { return }
callback!(0,data)
break
case .video(let fileUrl):
let data = NSData(contentsOf: fileUrl)
guard callback != nil else { return }
callback!(1,data)
break
default:
break
}
}
func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) {
guard callback != nil else { return }
callback!(-1,result.photoAssets)
}
func deleteAssets(_ assets:[PHAsset] = []) -> Void {
if assets.count > 0 {
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.deleteAssets(assets as NSFastEnumeration)
}) { success, error in
if success {
print("删除成功")
} else if let error = error {
print("删除失败: \(error.localizedDescription)")
}
}
}
}
static let share = SecretPhotoManager()
var callback:((Int,Any)->Void)?
func show(_ type:Int) -> Void {
if type == 0 {
let config = CameraConfiguration()
let vc = CameraController(config: config, type: .all, delegate: self)
guard let root = cWindow?.rootViewController else { return }
root.present(vc, animated: true)
}else{
var config = PickerConfiguration()
config.selectMode = .multiple
config.maximumSelectedCount = 4
let vc = PhotoPickerController(picker: config, delegate: self)
guard let root = cWindow?.rootViewController else { return }
root.present(vc, animated: true)
}
}
}
......@@ -6,7 +6,7 @@
//
import Foundation
//
enum AnimationStatus {
case end
......
......@@ -28,7 +28,7 @@ extension UIView {
}
func cornerCut(radius:CGFloat,corner:UIRectCorner){
let maskPath = UIBezierPath.init(roundedRect: bounds, byRoundingCorners: corner, cornerRadii: CGSize.init(width: radius, height: radius))
let maskLayer = CAShapeLayer()
maskLayer.frame = bounds
......
//
// NSString+Extension.swift
// PhoneManager
//
// Created by edy on 2025/4/1.
//
import Foundation
import UIKit
import AVFoundation
extension String {
// 获取文档路径
func document() -> URL {
let document = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
return document.appendingPathComponent(self)
}
func af() -> String {
return NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first ?? ""
}
func loadPhotoOrVideo( _ pv:((Float64,UIImage)->Void) ) -> Void {
let path = self.af() + "/SecretIm/"
let abe = path + self
if self.hasSuffix(".png") {
guard let icon = UIImage(contentsOfFile: abe) else {
return pv(-1,UIImage())
}
return pv(-1,icon)
}else{
let url = "SecretIm".document().appendingPathComponent(self)
let asset = AVAsset(url: url)
let imageGenerator = AVAssetImageGenerator(asset: asset)
imageGenerator.appliesPreferredTrackTransform = true
let duration = asset.duration
do {
let cgImage = try imageGenerator.copyCGImage(at: CMTime(value: 0, timescale: 1), actualTime: nil)
pv(CMTimeGetSeconds(duration) ,UIImage(cgImage: cgImage))
} catch {
pv(-1,UIImage() )
}
}
}
}
extension URL {
// 获取 路径下所有文件
func directorChildFile() -> [String] {
let fileManager = FileManager.default
let has = fileManager.fileExists(atPath: self.pathExtension )
do {
let fileNames = try fileManager.contentsOfDirectory(atPath: self.absoluteString)
var filesOnly: [String] = []
for fileName in fileNames {
let fullPath = (self.absoluteString as NSString).appendingPathComponent(fileName)
var isDirectory: ObjCBool = false
if fileManager.fileExists(atPath: fullPath, isDirectory: &isDirectory), !isDirectory.boolValue {
filesOnly.append(fileName)
}
}
return filesOnly
} catch {
print("获取文件列表失败: \(error.localizedDescription)")
return []
}
}
// 是否是文件夹
func isDirect(_ create:Bool = true) -> Bool {
var isDirectory: ObjCBool = false
let exists = FileManager.default.fileExists(atPath: self.absoluteString, isDirectory: &isDirectory)
if exists && isDirectory.boolValue {
}else{
if create {
do {
try FileManager.default.createDirectory(at: self, withIntermediateDirectories: false, attributes: nil)
}catch{
}
}
}
return exists && isDirectory.boolValue
}
}
......@@ -9,10 +9,12 @@
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
<key>NSUserActivityTypes</key>
<array>
<string>LaunchAppIntent</string>
</array>
<key>NSUserActivityTypes</key>
<array>
<string>LaunchAppIntent</string>
</array>
<key>PHPhotoLibraryPreventAutomaticLimitedAccessAlert</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
......
......@@ -10,5 +10,7 @@ target 'PhoneManager' do
pod 'lottie-ios'
pod 'SnapKit'
pod 'OpenCV', '~> 4.0.0'
pod 'HXPhotoPicker'
end
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