Commit ebf80e73 authored by CZ1004's avatar CZ1004

充电壁纸

parent 27d2a238
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>IntentsRestrictedWhileLocked</key>
<array/>
<key>IntentsRestrictedWhileProtectedDataUnavailable</key>
<array/>
<key>IntentsSupported</key>
<array>
<string>ChargeShowIntent</string>
<string>INSearchForMessagesIntent</string>
<string>INSendMessageIntent</string>
<string>INSetMessageAttributeIntent</string>
</array>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.intents-service</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).IntentHandler</string>
</dict>
</dict>
</plist>
//
// IntentHandler.swift
// ChargeShow
//
// Created by edy on 2025/4/7.
//
import Intents
// As an example, this class is set up to handle Message intents.
// You will want to replace this or add other intents as appropriate.
// The intents you wish to handle must be declared in the extension's Info.plist.
// You can test your example integration by saying things to Siri like:
// "Send a message using <myApp>"
// "<myApp> John saying hello"
// "Search for messages in <myApp>"
class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchForMessagesIntentHandling, INSetMessageAttributeIntentHandling {
override func handler(for intent: INIntent) -> Any {
// This is the default implementation. If you want different objects to handle different intents,
// you can override this and return the handler you want for that particular intent.
print("有反应么")
return self
}
// MARK: - INSendMessageIntentHandling
// Implement resolution methods to provide additional information about your intent (optional).
func resolveRecipients(for intent: INSendMessageIntent, with completion: @escaping ([INSendMessageRecipientResolutionResult]) -> Void) {
if let recipients = intent.recipients {
// If no recipients were provided we'll need to prompt for a value.
if recipients.count == 0 {
completion([INSendMessageRecipientResolutionResult.needsValue()])
return
}
var resolutionResults = [INSendMessageRecipientResolutionResult]()
for recipient in recipients {
let matchingContacts = [recipient] // Implement your contact matching logic here to create an array of matching contacts
switch matchingContacts.count {
case 2 ... Int.max:
// We need Siri's help to ask user to pick one from the matches.
resolutionResults += [INSendMessageRecipientResolutionResult.disambiguation(with: matchingContacts)]
case 1:
// We have exactly one matching contact
resolutionResults += [INSendMessageRecipientResolutionResult.success(with: recipient)]
case 0:
// We have no contacts matching the description provided
resolutionResults += [INSendMessageRecipientResolutionResult.unsupported()]
default:
break
}
}
completion(resolutionResults)
} else {
completion([INSendMessageRecipientResolutionResult.needsValue()])
}
}
func resolveContent(for intent: INSendMessageIntent, with completion: @escaping (INStringResolutionResult) -> Void) {
if let text = intent.content, !text.isEmpty {
completion(INStringResolutionResult.success(with: text))
} else {
completion(INStringResolutionResult.needsValue())
}
}
// Once resolution is completed, perform validation on the intent and provide confirmation (optional).
func confirm(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) {
// Verify user is authenticated and your app is ready to send a message.
let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
let response = INSendMessageIntentResponse(code: .ready, userActivity: userActivity)
completion(response)
}
// Handle the completed intent (required).
func handle(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) {
// Implement your application logic to send a message here.
let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
let response = INSendMessageIntentResponse(code: .success, userActivity: userActivity)
completion(response)
}
// Implement handlers for each intent you wish to handle. As an example for messages, you may wish to also handle searchForMessages and setMessageAttributes.
// MARK: - INSearchForMessagesIntentHandling
func handle(intent: INSearchForMessagesIntent, completion: @escaping (INSearchForMessagesIntentResponse) -> Void) {
// Implement your application logic to find a message that matches the information in the intent.
let userActivity = NSUserActivity(activityType: NSStringFromClass(INSearchForMessagesIntent.self))
let response = INSearchForMessagesIntentResponse(code: .success, userActivity: userActivity)
// Initialize with found message's attributes
response.messages = [INMessage(
identifier: "identifier",
content: "I am so excited about SiriKit!",
dateSent: Date(),
sender: INPerson(personHandle: INPersonHandle(value: "sarah@example.com", type: .emailAddress), nameComponents: nil, displayName: "Sarah", image: nil, contactIdentifier: nil, customIdentifier: nil),
recipients: [INPerson(personHandle: INPersonHandle(value: "+1-415-555-5555", type: .phoneNumber), nameComponents: nil, displayName: "John", image: nil, contactIdentifier: nil, customIdentifier: nil)]
)]
completion(response)
}
// MARK: - INSetMessageAttributeIntentHandling
func handle(intent: INSetMessageAttributeIntent, completion: @escaping (INSetMessageAttributeIntentResponse) -> Void) {
// Implement your application logic to set the message attribute here.
let userActivity = NSUserActivity(activityType: NSStringFromClass(INSetMessageAttributeIntent.self))
let response = INSetMessageAttributeIntentResponse(code: .success, userActivity: userActivity)
completion(response)
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>INEnums</key>
<array/>
<key>INIntentDefinitionModelVersion</key>
<string>1.2</string>
<key>INIntentDefinitionNamespace</key>
<string>hAB6zR</string>
<key>INIntentDefinitionSystemVersion</key>
<string>24D81</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>16C5032a</string>
<key>INIntentDefinitionToolsVersion</key>
<string>16.2</string>
<key>INIntents</key>
<array>
<dict>
<key>INIntentCategory</key>
<string>generic</string>
<key>INIntentConfigurable</key>
<true/>
<key>INIntentDescription</key>
<string>充电</string>
<key>INIntentDescriptionID</key>
<string>wDHi0A</string>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key></key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationUpdatesLinked</key>
<true/>
</dict>
</dict>
<key>INIntentName</key>
<string>ChargeShow</string>
<key>INIntentParameterCombinations</key>
<dict>
<key></key>
<dict>
<key>INIntentParameterCombinationIsPrimary</key>
<true/>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
</dict>
</dict>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
</dict>
<key>INIntentTitle</key>
<string>Charge Show</string>
<key>INIntentTitleID</key>
<string>wwbZJW</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>Do</string>
</dict>
</array>
<key>INTypes</key>
<array/>
</dict>
</plist>
This diff is collapsed.
...@@ -18,6 +18,8 @@ class ChargeInfoViewController:BaseViewController { ...@@ -18,6 +18,8 @@ class ChargeInfoViewController:BaseViewController {
var type:ChargeInfoType? var type:ChargeInfoType?
var flag : Int?
var isShowBack:Bool? { var isShowBack:Bool? {
didSet { didSet {
...@@ -43,7 +45,8 @@ class ChargeInfoViewController:BaseViewController { ...@@ -43,7 +45,8 @@ class ChargeInfoViewController:BaseViewController {
lazy var settingView:ChargeInfoSettingView = { lazy var settingView:ChargeInfoSettingView = {
let sview:ChargeInfoSettingView = ChargeInfoSettingView(frame: CGRect(x: 0, y: 0, width: view.width, height: 78 + safeHeight)) let sview:ChargeInfoSettingView = ChargeInfoSettingView(frame: CGRect(x: 0, y: 0, width: view.width, height: 78 + safeHeight))
sview.model = self.model
sview.flag = self.flag
sview.isHidden = type == .setting ? false : true sview.isHidden = type == .setting ? false : true
return sview return sview
...@@ -61,9 +64,9 @@ class ChargeInfoViewController:BaseViewController { ...@@ -61,9 +64,9 @@ class ChargeInfoViewController:BaseViewController {
} }
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
self.barHidden = true self.barHidden = true
titleView.model.title = "" titleView.model.title = ""
......
...@@ -38,9 +38,15 @@ class ChargeViewController:BaseViewController { ...@@ -38,9 +38,15 @@ class ChargeViewController:BaseViewController {
guard let self else {return} guard let self else {return}
if let cModel = model as? ChargeDataModel { if let cModel = model as? ChargeDataModel {
sview.callOrder = {[weak self] flag in
guard let self else {return}
let vc:ChargeInfoViewController = ChargeInfoViewController(model: cModel, type: ChargeInfoViewController.ChargeInfoType.setting)
vc.flag = flag as? Int
self.navigationController?.pushViewController(vc, animated: true)
}
let vc:ChargeInfoViewController = ChargeInfoViewController(model: cModel, type: ChargeInfoViewController.ChargeInfoType.setting)
self.navigationController?.pushViewController(vc, animated: true)
} }
} }
} }
......
...@@ -10,11 +10,35 @@ import Foundation ...@@ -10,11 +10,35 @@ import Foundation
struct ChargeDataModel { struct ChargeDataModel {
var isFree:Bool var isFree:Bool
var CoverImage:UIImage var coverImage:UIImage?
var url : URL var url : URL
init(isFree: Bool, CoverImage: UIImage, url: URL) { init(isFree: Bool, coverImage: UIImage, url: URL) {
self.isFree = isFree self.isFree = isFree
self.CoverImage = CoverImage self.coverImage = coverImage
self.url = url self.url = url
} }
func toDictionary() -> [String: Any] {
if let imageData = coverImage!.pngData() {
print("成功将图片转换为 PNG 格式的 Data,数据大小: \(imageData.count) 字节")
return [
"isFree": isFree,
"coverImage": imageData,
"url": url.absoluteString
]
} else {
print("转换失败")
}
return [:]
}
init?(dictionary: [String: Any]) {
guard let isFree = dictionary["isFree"] as? Bool,
let coverImageData = dictionary["coverImage"] as? Data,
let url = dictionary["url"] as? String else {
return nil
}
self.isFree = isFree
self.coverImage = UIImage(data: coverImageData)!
self.url = URL(string: url)!
}
} }
...@@ -43,9 +43,8 @@ func loadVideoItems() -> [ChargeDataModel]{ ...@@ -43,9 +43,8 @@ func loadVideoItems() -> [ChargeDataModel]{
do { do {
let cgImage = try imageGenerator.copyCGImage(at: time, actualTime: nil) let cgImage = try imageGenerator.copyCGImage(at: time, actualTime: nil)
let image = UIImage(cgImage: cgImage) let image = UIImage(cgImage: cgImage)
let model = ChargeDataModel(isFree: true, CoverImage: image, url: url) let model = ChargeDataModel(isFree: true, coverImage: image, url: url)
dataArray.append(model) dataArray.append(model)
print("获取视频成功")
} catch { } catch {
print("获取视频图片出错: \(error.localizedDescription)") print("获取视频图片出错: \(error.localizedDescription)")
} }
......
...@@ -9,6 +9,10 @@ import UIKit ...@@ -9,6 +9,10 @@ import UIKit
class ChargeInfoSettingView:UIView { class ChargeInfoSettingView:UIView {
var model : ChargeDataModel?
var flag : Int?
lazy var settingBtn:UIButton = { lazy var settingBtn:UIButton = {
let sview:UIButton = UIButton() let sview:UIButton = UIButton()
...@@ -48,8 +52,19 @@ class ChargeInfoSettingView:UIView { ...@@ -48,8 +52,19 @@ class ChargeInfoSettingView:UIView {
} }
@objc func settingBtnClick() { @objc func settingBtnClick() {
// 存储到userDefaults
UserDefaults.standard.set(String(flag!), forKey: "chargePicInfo")
let alert = UIAlertController(title: nil, message: "完成!", preferredStyle: .alert)
self.responderViewController()?.present(alert, animated: true, completion: nil)
// 2 秒后关闭弹窗
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
alert.dismiss(animated: true, completion: nil)
self.responderViewController()?.navigationController?.popViewController(animated: true)
}
} }
} }
...@@ -35,7 +35,7 @@ class ChargeVideoPlayingView: UIView { ...@@ -35,7 +35,7 @@ class ChargeVideoPlayingView: UIView {
return return
} }
// 将编码后的字符串转换为 URL 对象 // 将编码后的字符串转换为 URL 对象
guard let encodedURL = URL(string: encodedURLString) else { guard URL(string: encodedURLString) != nil else {
print("无法创建编码后的 URL") print("无法创建编码后的 URL")
return return
} }
......
...@@ -10,7 +10,9 @@ import AVFoundation ...@@ -10,7 +10,9 @@ import AVFoundation
class ChargeView:UIView { class ChargeView:UIView {
var callBack:callBack<Any> = {model in } var callBack : callBack<Any> = {model in }
var callOrder : callBack<Any> = {flag in }
let footerID:String = "footerID" let footerID:String = "footerID"
...@@ -89,7 +91,7 @@ extension ChargeView:WaterfallMutiSectionDelegate,UICollectionViewDataSource,UIC ...@@ -89,7 +91,7 @@ extension ChargeView:WaterfallMutiSectionDelegate,UICollectionViewDataSource,UIC
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ChargeViewCollectionCell.identifiers, for: indexPath) as! ChargeViewCollectionCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ChargeViewCollectionCell.identifiers, for: indexPath) as! ChargeViewCollectionCell
cell.flag = indexPath.row
cell.model = models[indexPath.row] cell.model = models[indexPath.row]
return cell return cell
...@@ -100,6 +102,9 @@ extension ChargeView:WaterfallMutiSectionDelegate,UICollectionViewDataSource,UIC ...@@ -100,6 +102,9 @@ extension ChargeView:WaterfallMutiSectionDelegate,UICollectionViewDataSource,UIC
let model = models[indexPath.row] let model = models[indexPath.row]
self.callBack(model) self.callBack(model)
self.callOrder(indexPath.row)
} }
func collectionView(_ collectionView: UICollectionView, func collectionView(_ collectionView: UICollectionView,
......
...@@ -12,6 +12,8 @@ class ChargeViewCollectionCell:UICollectionViewCell { ...@@ -12,6 +12,8 @@ class ChargeViewCollectionCell:UICollectionViewCell {
static let identifiers = "ChargeViewCollectionCellID" static let identifiers = "ChargeViewCollectionCellID"
var flag : Int?
var videoURL : URL? var videoURL : URL?
lazy var backImageView:UIImageView = { lazy var backImageView:UIImageView = {
...@@ -66,7 +68,7 @@ class ChargeViewCollectionCell:UICollectionViewCell { ...@@ -66,7 +68,7 @@ class ChargeViewCollectionCell:UICollectionViewCell {
guard let self else {return} guard let self else {return}
self.backImageView.image = model.CoverImage self.backImageView.image = model.coverImage
self.isFreeBtn.isHidden = model.isFree self.isFreeBtn.isHidden = model.isFree
......
...@@ -122,8 +122,15 @@ class HomeViewController:BaseViewController { ...@@ -122,8 +122,15 @@ class HomeViewController:BaseViewController {
isShowPay = true isShowPay = true
if BatteryMonitorManager.shared.getBatteryIsCharging() { if BatteryMonitorManager.shared.getBatteryIsCharging() {
// 从字典里面取 如果有
let vc:ChargeInfoViewController = ChargeInfoViewController(model:loadVideoItems().first, type: ChargeInfoViewController.ChargeInfoType.charge) var tempModel : ChargeDataModel?
if UserDefaults.standard.object(forKey: "chargePicInfo") == nil {
tempModel = loadVideoItems().first
}else{
let flag : String = UserDefaults.standard.object(forKey: "chargePicInfo") as! String
tempModel = loadVideoItems()[Int(flag)!]
}
let vc:ChargeInfoViewController = ChargeInfoViewController(model:tempModel, type: ChargeInfoViewController.ChargeInfoType.charge)
self.navigationController?.pushViewController(vc, animated: false) self.navigationController?.pushViewController(vc, animated: false)
......
...@@ -84,8 +84,19 @@ class BatteryMonitorManager { ...@@ -84,8 +84,19 @@ class BatteryMonitorManager {
func getBatteryIsCharging() -> Bool { func getBatteryIsCharging() -> Bool {
UIDevice.current.isBatteryMonitoringEnabled = true UIDevice.current.isBatteryMonitoringEnabled = true
switch UIDevice.current.batteryState {
return UIDevice.current.batteryState == .charging case.unknown:
print("电池状态未知")
case.unplugged:
print("电池未充电")
case.charging:
print("电池正在充电")
case.full:
print("电池已充满")
@unknown default:
break
}
return UIDevice.current.batteryState == .charging || UIDevice.current.batteryState == .full
} }
// MARK: - Private Methods // MARK: - Private Methods
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
</dict> </dict>
<key>NSUserActivityTypes</key> <key>NSUserActivityTypes</key>
<array> <array>
<string>ChargeShowIntent</string>
<string>LaunchAppIntent</string> <string>LaunchAppIntent</string>
<string>Charge Intents</string>
</array> </array>
<key>PHPhotoLibraryPreventAutomaticLimitedAccessAlert</key> <key>PHPhotoLibraryPreventAutomaticLimitedAccessAlert</key>
<true/> <true/>
......
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