Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
PhoneManager
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yang
PhoneManager
Commits
6cf21672
Commit
6cf21672
authored
Apr 27, 2025
by
CZ1004
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修复】1、压缩完成删除逻辑更新
2、充电流程更新 3、添加获取内购价格缓存
parent
d6da802c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
57 deletions
+127
-57
AdvTipDeleteView.swift
...r/Class/Session/Advertisement/View/AdvTipDeleteView.swift
+16
-6
CompressCompletedViewController.swift
...Compress/Controller/CompressCompletedViewController.swift
+25
-21
HomeViewController.swift
...er/Class/Session/Home/Controller/HomeViewController.swift
+7
-25
HomePayModel.swift
PhoneManager/Class/Session/Pay/Model/HomePayModel.swift
+79
-3
HomePayViewController.swift
...ss/Session/Pay/ViewController/HomePayViewController.swift
+0
-2
No files found.
PhoneManager/Class/Session/Advertisement/View/AdvTipDeleteView.swift
View file @
6cf21672
...
@@ -332,14 +332,16 @@ class ImageCell: UICollectionViewCell {
...
@@ -332,14 +332,16 @@ class ImageCell: UICollectionViewCell {
class
CenteredGroupCollectionViewLayout
:
UICollectionViewFlowLayout
{
class
CenteredGroupCollectionViewLayout
:
UICollectionViewFlowLayout
{
override
func
layoutAttributesForElements
(
in
rect
:
CGRect
)
->
[
UICollectionViewLayoutAttributes
]?
{
override
func
layoutAttributesForElements
(
in
rect
:
CGRect
)
->
[
UICollectionViewLayoutAttributes
]?
{
guard
let
attributes
=
super
.
layoutAttributesForElements
(
in
:
rect
)
else
{
return
nil
}
guard
let
attributes
=
super
.
layoutAttributesForElements
(
in
:
rect
)
else
{
return
nil
}
guard
let
collectionView
=
collectionView
else
{
return
attributes
}
guard
let
collectionView
=
collectionView
,
!
attributes
.
isEmpty
else
{
return
attributes
}
// 计算内容总宽度
// 计算内容总宽度
var
contentWidth
:
CGFloat
=
0
var
contentWidth
:
CGFloat
=
0
for
attribute
in
attributes
{
for
(
index
,
attribute
)
in
attributes
.
enumerated
()
{
contentWidth
+=
attribute
.
frame
.
width
contentWidth
+=
attribute
.
frame
.
width
if
index
<
attributes
.
count
-
1
{
contentWidth
+=
minimumInteritemSpacing
}
}
}
contentWidth
+=
minimumInteritemSpacing
*
CGFloat
(
attributes
.
count
-
1
)
contentWidth
+=
sectionInset
.
left
+
sectionInset
.
right
contentWidth
+=
sectionInset
.
left
+
sectionInset
.
right
// 计算偏移量
// 计算偏移量
...
@@ -351,11 +353,19 @@ class CenteredGroupCollectionViewLayout: UICollectionViewFlowLayout {
...
@@ -351,11 +353,19 @@ class CenteredGroupCollectionViewLayout: UICollectionViewFlowLayout {
// 调整布局属性
// 调整布局属性
var
runningOffset
:
CGFloat
=
offsetX
+
sectionInset
.
left
var
runningOffset
:
CGFloat
=
offsetX
+
sectionInset
.
left
for
attribute
in
attributes
{
for
(
index
,
attribute
)
in
attributes
.
enumerated
()
{
attribute
.
frame
.
origin
.
x
=
runningOffset
attribute
.
frame
.
origin
.
x
=
runningOffset
runningOffset
+=
attribute
.
frame
.
width
+
minimumInteritemSpacing
if
index
<
attributes
.
count
-
1
{
runningOffset
+=
attribute
.
frame
.
width
+
minimumInteritemSpacing
}
else
{
runningOffset
+=
attribute
.
frame
.
width
}
}
}
return
attributes
return
attributes
}
}
}
override
func
shouldInvalidateLayout
(
forBoundsChange
newBounds
:
CGRect
)
->
Bool
{
return
true
}
}
PhoneManager/Class/Session/Compress/Controller/CompressCompletedViewController.swift
View file @
6cf21672
...
@@ -296,28 +296,32 @@ class CompressCompletedViewController : BaseViewController{
...
@@ -296,28 +296,32 @@ class CompressCompletedViewController : BaseViewController{
}
}
// 删除文件逻辑【系统自动提示是否删除】
// 删除文件逻辑【系统自动提示是否删除】
var
count
=
0
var
idents
:[
String
]
=
[]
for
data
in
self
.
model
!
{
for
ele
in
self
.
model
!
{
let
fetchResult
=
PHAsset
.
fetchAssets
(
withLocalIdentifiers
:
[
data
.
ident
],
options
:
nil
)
idents
.
append
(
ele
.
ident
)
let
fileSize
=
FileTool
()
.
calculateTotalAssetSize
(
fetchResult
:
fetchResult
)
}
let
assetToDelete
=
fetchResult
.
firstObject
let
fetchResult
=
PHAsset
.
fetchAssets
(
withLocalIdentifiers
:
idents
,
options
:
nil
)
PHPhotoLibrary
.
shared
()
.
performChanges
({
let
fileSize
=
FileTool
()
.
calculateTotalAssetSize
(
fetchResult
:
fetchResult
)
PHAssetChangeRequest
.
deleteAssets
([
assetToDelete
]
as
NSFastEnumeration
)
let
assetToDelete
=
fetchResult
.
firstObject
}){
success
,
error
in
PHPhotoLibrary
.
shared
()
.
performChanges
({
if
(
success
){
PHAssetChangeRequest
.
deleteAssets
([
assetToDelete
]
as
NSFastEnumeration
)
self
.
updateCompressData
(
flag
:
data
.
ident
)
}){
success
,
error
in
let
deleteModel
=
AssetModel
(
localIdentifier
:
data
.
ident
,
assetSize
:
data
.
orgSize
,
createDate
:
data
.
createDate
)
if
(
success
){
PhotoDataManager
.
manager
.
removeDataWhenDeleteInPage
(
data
:
[
deleteModel
])
var
models
:[
AssetModel
]
=
[]
print
(
"删除文件成功"
)
var
count
=
0
self
.
showDeleteSuccess
(
fileCount
:
1
,
fileSize
:
fileSize
)
for
ele
in
self
.
model
!
{
}
else
{
count
=
count
+
1
if
let
error
=
error
{
self
.
updateCompressData
(
flag
:
ele
.
ident
)
print
(
"删除文件时出错:
\(
error
.
localizedDescription
)
"
)
let
deleteModel
=
AssetModel
(
localIdentifier
:
ele
.
ident
,
assetSize
:
ele
.
orgSize
,
createDate
:
ele
.
createDate
)
}
models
.
append
(
deleteModel
)
}
}
count
=
count
+
1
PhotoDataManager
.
manager
.
removeDataWhenDeleteInPage
(
data
:
models
)
if
count
==
self
.
model
?
.
count
{
print
(
"删除文件成功"
)
self
.
jumpToCompressVC
()
self
.
showDeleteSuccess
(
fileCount
:
count
,
fileSize
:
fileSize
)
self
.
jumpToCompressVC
()
}
else
{
if
let
error
=
error
{
print
(
"删除文件时出错:
\(
error
.
localizedDescription
)
"
)
}
}
}
}
}
}
...
...
PhoneManager/Class/Session/Home/Controller/HomeViewController.swift
View file @
6cf21672
...
@@ -94,8 +94,6 @@ class HomeViewController:BaseViewController {
...
@@ -94,8 +94,6 @@ class HomeViewController:BaseViewController {
// 调用下追踪权限
// 调用下追踪权限
checkTrackingAuthorization
()
checkTrackingAuthorization
()
NotificationManager
()
.
configNotifications
()
let
dataUpdated
=
Notification
.
Name
(
"DataUpdatedNotification"
)
let
dataUpdated
=
Notification
.
Name
(
"DataUpdatedNotification"
)
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
handleDataUpdated(_:)
)
,
name
:
dataUpdated
,
object
:
nil
)
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
handleDataUpdated(_:)
)
,
name
:
dataUpdated
,
object
:
nil
)
...
@@ -128,11 +126,7 @@ class HomeViewController:BaseViewController {
...
@@ -128,11 +126,7 @@ class HomeViewController:BaseViewController {
let
homeSimilarImageResourceUpdate
=
Notification
.
Name
(
"HomeSimilarImageResourceUpdate"
)
let
homeSimilarImageResourceUpdate
=
Notification
.
Name
(
"HomeSimilarImageResourceUpdate"
)
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
handleHomeSimilarImageResourceUpdate(_:)
)
,
name
:
homeSimilarImageResourceUpdate
,
object
:
nil
)
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
handleHomeSimilarImageResourceUpdate(_:)
)
,
name
:
homeSimilarImageResourceUpdate
,
object
:
nil
)
// // 充电通知
// let applicationDidBecomeActive = Notification.Name("applicationDidBecomeActive")
// NotificationCenter.default.addObserver(self, selector: #selector(handleApplicationDidBecomeActive(_:)), name: applicationDidBecomeActive, object: nil)
//
homeView
=
HomeView
(
frame
:
view
.
bounds
)
homeView
=
HomeView
(
frame
:
view
.
bounds
)
...
@@ -200,12 +194,8 @@ class HomeViewController:BaseViewController {
...
@@ -200,12 +194,8 @@ class HomeViewController:BaseViewController {
self
.
junmToModule
(
cIndex
,
self
)
self
.
junmToModule
(
cIndex
,
self
)
}
}
}
}
}
}
view
.
addSubview
(
homeView
!
)
view
.
addSubview
(
homeView
!
)
}
}
func
setupData
()
{
func
setupData
()
{
...
@@ -240,13 +230,9 @@ class HomeViewController:BaseViewController {
...
@@ -240,13 +230,9 @@ class HomeViewController:BaseViewController {
override
func
viewWillAppear
(
_
animated
:
Bool
)
{
override
func
viewWillAppear
(
_
animated
:
Bool
)
{
super
.
viewWillAppear
(
animated
)
super
.
viewWillAppear
(
animated
)
// 可能是删除数据,重新获取下
PhotoDataManager
.
manager
.
loadFromFileSystem
(
resultModel
:
{[
weak
self
]
model
in
// 获取主页数据
DispatchQueue
.
main
.
async
{
setupData
()
self
?
.
homeView
?
.
model
=
model
self
?
.
reloadCollectionView
()
}
})
if
!
isShowCharge
{
if
!
isShowCharge
{
if
BatteryMonitorManager
.
shared
.
getBatteryIsCharging
()
{
if
BatteryMonitorManager
.
shared
.
getBatteryIsCharging
()
{
...
@@ -303,15 +289,11 @@ class HomeViewController:BaseViewController {
...
@@ -303,15 +289,11 @@ class HomeViewController:BaseViewController {
}
}
if
!
isShowPay
{
if
!
isShowPay
{
// 获取主页数据
setupData
()
isShowPay
=
true
isShowPay
=
true
if
HomePayModel
.
share
.
isNoAd
==
false
{
if
HomePayModel
.
share
.
isNoAd
==
false
{
HomePayViewController
.
show
{}
HomePayViewController
.
show
{
NotificationManager
()
.
configNotifications
()
}
}
}
}
}
...
...
PhoneManager/Class/Session/Pay/Model/HomePayModel.swift
View file @
6cf21672
...
@@ -13,6 +13,9 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs
...
@@ -13,6 +13,9 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs
static
let
share
:
HomePayModel
=
HomePayModel
()
static
let
share
:
HomePayModel
=
HomePayModel
()
private
let
userDefaults
=
UserDefaults
.
standard
private
let
productCacheKey
=
"IAPProductCache"
enum
PayState
{
enum
PayState
{
case
Subscribe
// 订阅
case
Subscribe
// 订阅
case
NonConsum
// 非消耗型
case
NonConsum
// 非消耗型
...
@@ -82,12 +85,78 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs
...
@@ -82,12 +85,78 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs
}
}
}
}
func
cacheProducts
(
_
products
:
[
SKProduct
])
{
var
productCache
=
[[
String
:
Any
]]()
for
product
in
products
{
let
productInfo
:
[
String
:
Any
]
=
[
"productIdentifier"
:
product
.
productIdentifier
,
"localizedTitle"
:
product
.
localizedTitle
,
"localizedDescription"
:
product
.
localizedDescription
,
"price"
:
product
.
price
.
doubleValue
,
"priceLocale"
:
product
.
priceLocale
.
identifier
]
productCache
.
append
(
productInfo
)
}
userDefaults
.
set
(
productCache
,
forKey
:
productCacheKey
)
}
func
getCachedProduct
(
forIdentifier
identifier
:
[
String
])
->
[
SKProduct
]?
{
var
products
:
[
SKProduct
]
=
[]
// 从 UserDefaults 中获取缓存数据
if
let
productCache
=
userDefaults
.
object
(
forKey
:
productCacheKey
)
as?
[[
String
:
Any
]]
{
for
item
in
productCache
{
// 从字典中提取价格和价格区域设置信息
let
price
=
NSDecimalNumber
(
value
:
item
[
"price"
]
as?
Double
??
0
)
let
priceLocaleIdentifier
=
item
[
"priceLocale"
]
as?
String
??
""
let
priceLocale
=
Locale
(
identifier
:
priceLocaleIdentifier
)
// 创建 SKProduct 实例
let
mockProduct
=
SKProduct
()
// 设置商品标识符
if
let
firstIdentifier
=
identifier
.
first
{
mockProduct
.
setValue
(
firstIdentifier
,
forKey
:
"productIdentifier"
)
}
// 设置商品本地化标题
mockProduct
.
setValue
(
item
[
"localizedTitle"
]
as?
String
,
forKey
:
"localizedTitle"
)
// 设置商品本地化描述
mockProduct
.
setValue
(
item
[
"localizedDescription"
]
as?
String
,
forKey
:
"localizedDescription"
)
// 设置商品价格
mockProduct
.
setValue
(
price
,
forKey
:
"price"
)
// 设置商品价格的区域设置
mockProduct
.
setValue
(
priceLocale
,
forKey
:
"priceLocale"
)
// 将商品添加到结果数组中
products
.
append
(
mockProduct
)
}
}
return
products
}
func
fetchProducts
()
{
func
fetchProducts
()
{
Print
(
"获取商品信息"
)
// 看缓存里面有没有 有的话直接返回
if
let
cachedProduct
=
self
.
getCachedProduct
(
forIdentifier
:
productIdentifiers
)
{
var
ps
:[
SKProduct
?]
=
[
nil
,
nil
]
if
cachedProduct
.
count
>=
2
{
if
cachedProduct
.
first
?
.
productIdentifier
==
productIdentifiers
.
first
{
ps
[
0
]
=
cachedProduct
.
first
ps
[
1
]
=
cachedProduct
.
last
}
else
{
ps
[
1
]
=
cachedProduct
.
first
ps
[
0
]
=
cachedProduct
.
last
}
}
else
{
ps
=
cachedProduct
}
self
.
product
=
ps
self
.
storeCall
(
ps
)
Print
(
"获取商品信息成功--读取缓存数据"
)
}
// 后续重新获取价格缓存
BackgroundTaskManager
.
share
.
startTask
()
BackgroundTaskManager
.
share
.
startTask
()
let
request
=
SKProductsRequest
(
productIdentifiers
:
Set
(
productIdentifiers
))
let
request
=
SKProductsRequest
(
productIdentifiers
:
Set
(
productIdentifiers
))
request
.
delegate
=
self
request
.
delegate
=
self
request
.
start
()
request
.
start
()
Print
(
"获取商品信息"
)
DispatchQueue
.
global
()
.
asyncAfter
(
deadline
:
.
now
()
+
15
)
{
DispatchQueue
.
global
()
.
asyncAfter
(
deadline
:
.
now
()
+
15
)
{
request
.
cancel
()
request
.
cancel
()
BackgroundTaskManager
.
share
.
endTask
()
BackgroundTaskManager
.
share
.
endTask
()
...
@@ -112,10 +181,17 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs
...
@@ -112,10 +181,17 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs
ps
=
products
ps
=
products
}
}
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
.
now
()
+
0.2
,
execute
:
{
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
.
now
()
+
0.2
,
execute
:
{
self
.
product
=
ps
Print
(
"获取商品信息成功"
)
Print
(
"获取商品信息成功"
)
if
self
.
getCachedProduct
(
forIdentifier
:
self
.
productIdentifiers
)?
.
count
==
0
{
Print
(
"获取商品信息成功--缓存没有数据由请求提供"
)
self
.
product
=
ps
self
.
storeCall
(
ps
)
}
Print
(
"开始缓存商品信息"
)
self
.
cacheProducts
(
products
)
Print
(
"缓存商品信息成功"
)
BackgroundTaskManager
.
share
.
endTask
()
BackgroundTaskManager
.
share
.
endTask
()
self
.
storeCall
(
ps
)
})
})
}
}
...
...
PhoneManager/Class/Session/Pay/ViewController/HomePayViewController.swift
View file @
6cf21672
...
@@ -113,8 +113,6 @@ extension HomePayViewController {
...
@@ -113,8 +113,6 @@ extension HomePayViewController {
let
p2
=
currentProduct
?
.
last
let
p2
=
currentProduct
?
.
last
else
{
return
}
else
{
return
}
homePayView
?
.
reloadSKPorduct
(
product
:
p1
,
product1
:
p2
)
homePayView
?
.
reloadSKPorduct
(
product
:
p1
,
product1
:
p2
)
// homePayView?.product = p1
// homePayView?.product1 = p2
}
}
private
func
storeKeD
()
->
Void
{
private
func
storeKeD
()
->
Void
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment