Music_Player3/relax.offline.mp3.music/MP/Common/Base(公用基类)/Controllers/MP_LunchViewController.swift

234 lines
9.4 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 = 7
//
private lazy var currentTimes:TimeInterval = 0
//
private var completionBlock:(() -> Void)?
//A/B
private var isBeen:Bool = false
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .init(hex: "#000000")
timer = CADisplayLink(target: self, selector: #selector(timerActionClick(_ :)))
//
timer.preferredFramesPerSecond = 40
//线
timer.add(to: RunLoop.current, forMode: .common)
//
timer.isPaused = false
}
deinit {
timer.isPaused = true
//
timer.invalidate()
timer = nil
NotificationCenter.default.removeObserver(self)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
//
requestTrackingAuthorization { idfa in
}
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
MP_AnalyticsManager.shared.launch_pvAction()
}
//
@objc fileprivate func timerActionClick(_ link:CADisplayLink) {
if maxTimes > currentTimes {
//
currentTimes += 0.025
let value = currentTimes/maxTimes
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
progressView.setProgress(value)
}
//A/B
if isBeen == false {
//
isBeen = true
switchAOrBAction()
}
}else {
//
timer.isPaused = true
guard MP_NetWorkManager.shared.netWorkStatu != .reachable else {
if completionBlock != nil {
completionBlock!()
}else {
//A
print("ALog")
//A
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_aSide()
}
}
return
}
//
if completionBlock != nil {
completionBlock!()
}else {
//A
print("ALog")
//A
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_aSide()
}
}
}
}
//a/b
private func switchAOrBAction() {
//B
guard UserDefaults.standard.bool(forKey: "MP_Into_B") != true else {
//B
self.completionBlock = {
//b
print("BLog")
//BB
UserDefaults.standard.set(true, forKey: "MP_Into_B")
//B
MPPositive_BrowseLoadViewModel.shared.reloadBrowseLists()
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_positive()
}
}
return
}
MP_NetWorkManager.shared.performTaskNetWrokAvailable {
[weak self] in
guard let self = self else {return}
//B
MPPositive_BrowseLoadViewModel.shared.reloadBrowseLists()
//
MP_AnalyticsManager.shared.getOpenStatus { [weak self] open in
guard let self = self else {return}
if open {
//IP
//ip
MP_NetWorkManager.shared.requestIPInfo { statu in
if statu == true {
//b
print("BLog")
//BB
UserDefaults.standard.set(true, forKey: "MP_Into_B")
//
if self.maxTimes > self.currentTimes {
//
self.completionBlock = {
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_positive()
}
}
}else {
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_positive()
}
}
}else {
print("ALog")
//A
if self.maxTimes > self.currentTimes {
self.completionBlock = {
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_aSide()
}
}
}else {
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_aSide()
}
}
}
}
}else {
print("ALog")
//A
if self.maxTimes > self.currentTimes {
self.completionBlock = {
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_aSide()
}
}
}else {
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_aSide()
}
}
}
}
}
}
}