Music_Player3/relax.offline.mp3.music/MP/Common/Base(公用基类)/Controllers/MP_LunchViewController.swift
2024-06-19 18:32:15 +08:00

316 lines
12 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
import GoogleMobileAds
///
class MP_LunchViewController: UIViewController, GADFullScreenContentDelegate {
@IBOutlet weak var progressView: MP_Lunch_ProgressView!{
didSet{
progressView.layer.masksToBounds = true
}
}
//
private var timer:CADisplayLink!
//
private lazy var maxTimes:TimeInterval = 10
//
private lazy var currentTimes:TimeInterval = 0
//
private var completionBlock:(() -> Void)?
//A/B
private var isBeen:Bool = false
//广
private var adShowBlock:(() -> Void)?
//
private var switchBlock:(() -> Void)?
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
//
requestTrackingAuthorization { idfa in
}
}
view.backgroundColor = .init(hex: "#000000")
timer = CADisplayLink(target: self, selector: #selector(timerActionClick(_ :)))
//
timer.preferredFramesPerSecond = 10
//线
timer.add(to: RunLoop.current, forMode: .common)
//
timer.isPaused = false
//广
MP_AdMobManager.shared.loadSearchInterstitialAd { status in
if status {
print("成功加载搜索插页广告")
}else {
print("搜索插页广告加载失败")
}
}
MP_AdMobManager.shared.loadPlayInterstitialAd(.Play) { status in
if status {
print("成功加载播放插页广告")
}else {
print("播放插页广告加载失败")
}
}
MP_AdMobManager.shared.loadLibraryInterstitialAd { status in
if status {
print("成功加载曲库插页广告")
}else {
print("曲库插页广告加载失败")
}
}
MP_AdMobManager.shared.loadGlobalInterstitialAd { status in
if status {
print("成功加载全局插页广告")
}else {
print("全局插页广告加载失败")
}
}
//广
MP_AdMobManager.shared.showOpenAdIfAvailable(.ICE) { [weak self] ad in
guard let self = self else {return}
//广
adShowBlock = {
//
MP_AdMobManager.shared.setInterstitialSwitch(true)
MP_AdMobManager.shared.isShowingOpenAd = true
//
ad.fullScreenContentDelegate = self
ad.present(fromRootViewController: self)
}
}
switchBlock = {
[weak self] in
guard let self = self else {return}
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()
}
}
}
//
MP_CacheAndArchiverManager.shared.zhoujunfeng_checkAndCleanCacheFolder()
}
deinit {
timer.isPaused = true
//
timer.invalidate()
timer = nil
NotificationCenter.default.removeObserver(self)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
MP_AnalyticsManager.shared.launch_pvAction()
}
//
@objc fileprivate func timerActionClick(_ link:CADisplayLink) {
if maxTimes > currentTimes {
//
currentTimes += 0.1
let value = (currentTimes/maxTimes).isNaN ? 0:(currentTimes/maxTimes)
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
progressView.setProgress(value)
}
//A/B
if isBeen == false && currentTimes > 2 {
//
isBeen = true
switchAOrBAction()
}
}else {
//
timer.isPaused = true
//广
if adShowBlock != nil {
adShowBlock!()
}else {
switchBlock!()
}
}
}
//a/b
private func switchAOrBAction() {
//B
guard UserDefaults.standard.bool(forKey: "MP_Into_B") != true else {
//B
MPPositive_BrowseLoadViewModel.shared.reloadBrowseLists()
//B
self.completionBlock = {
//b
print("BLog")
//BB
UserDefaults.standard.set(true, forKey: "MP_Into_B")
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()
}
}
}
}
}
}
//MARK: - 广 GADFullScreenContentDelegate
//广
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
//广广
if switchBlock != nil {
switchBlock!()
}
if MP_AdMobManager.shared.completeOpenAdBlock != nil {
MP_AdMobManager.shared.completeOpenAdBlock!()
}
accessAppdelegate.setAudioSupport()
}
//广
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
//广广
if switchBlock != nil {
switchBlock!()
}
if MP_AdMobManager.shared.completeOpenAdBlock != nil {
MP_AdMobManager.shared.completeOpenAdBlock!()
}
accessAppdelegate.setAudioSupport()
}
}