Music_Player3/MusicPlayer/MP/Common/Base(公用基类)/Controllers/MP_LunchViewController.swift
2024-06-05 10:50:14 +08:00

137 lines
4.5 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// LunchViewController.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/3/27.
//
import UIKit
///
class MP_LunchViewController: UIViewController {
@IBOutlet weak var progressView: MP_Lunch_ProgressView!{
didSet{
progressView.layer.masksToBounds = true
}
}
//
private var timer:CADisplayLink!
//
private lazy var maxTimes:TimeInterval = 6
//
private lazy var currentTimes:TimeInterval = 0
//
private var completionBlock:(() -> Void)?
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .init(hex: "#000000")
timer = CADisplayLink(target: self, selector: #selector(timerActionClick(_ :)))
//
timer.preferredFramesPerSecond = 20
//线
timer.add(to: RunLoop.current, forMode: .common)
//idfa
_ = requestTrackingAuthorization(self)
#if DEBUG
self.completionBlock = {
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_positive()
}
}
#else
chekStatus()
#endif
//
timer.isPaused = false
}
//status
func chekStatus() {
MP_AnalyticsManager.shared.getOpenStatus { [weak self] open in
guard let self = self else {return}
if open {
//ip
MP_NetWorkManager.shared.requestIPInfo { statu in
if statu == true {
//b
print("BLog")
self.completionBlock = {
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_positive()
}
}
}else {
print("ALog")
//A
self.completionBlock = {
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_aSide()
}
}
}
}
}else {
print("ALog")
//A
completionBlock = {
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_aSide()
}
}
}
}
}
deinit {
//
timer.invalidate()
timer = nil
NotificationCenter.default.removeObserver(self)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
MP_AnalyticsManager.shared.launch_pvAction()
}
//
@objc fileprivate func timerActionClick(_ link:CADisplayLink) {
if maxTimes > currentTimes {
//
currentTimes += 0.05
let value = currentTimes/maxTimes
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
progressView.setProgress(value)
}
}else {
if completionBlock != nil {
completionBlock!()
}
}
}
}