diff --git a/WOKA.xcodeproj/project.pbxproj b/WOKA.xcodeproj/project.pbxproj index b02f032..8b316d4 100644 --- a/WOKA.xcodeproj/project.pbxproj +++ b/WOKA.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ 520CE6AF2C74999200974228 /* AppUpdateDM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 520CE6AE2C74999200974228 /* AppUpdateDM.swift */; }; 520CE6B12C74BB9D00974228 /* AppUpdateVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 520CE6B02C74BB9D00974228 /* AppUpdateVC.swift */; }; 5219C2C22C086D9C00A1DF4D /* DataTypeConversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5219C2C12C086D9B00A1DF4D /* DataTypeConversion.swift */; }; + 521E5A9D2CA1A5C800AEF131 /* GoogleInterstistialADSetup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 521E5A9C2CA1A5BE00AEF131 /* GoogleInterstistialADSetup.swift */; }; 522242662BFC74380085C632 /* MyListVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522242632BFC74380085C632 /* MyListVC.swift */; }; 522242682BFC74380085C632 /* TabBarVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522242652BFC74380085C632 /* TabBarVC.swift */; }; 5222426A2BFC7AFC0085C632 /* SideMenuVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522242692BFC7AFC0085C632 /* SideMenuVC.swift */; }; @@ -424,6 +425,7 @@ 520CE6AE2C74999200974228 /* AppUpdateDM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUpdateDM.swift; sourceTree = ""; }; 520CE6B02C74BB9D00974228 /* AppUpdateVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUpdateVC.swift; sourceTree = ""; }; 5219C2C12C086D9B00A1DF4D /* DataTypeConversion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataTypeConversion.swift; sourceTree = ""; }; + 521E5A9C2CA1A5BE00AEF131 /* GoogleInterstistialADSetup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoogleInterstistialADSetup.swift; sourceTree = ""; }; 522242632BFC74380085C632 /* MyListVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyListVC.swift; sourceTree = ""; }; 522242652BFC74380085C632 /* TabBarVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabBarVC.swift; sourceTree = ""; }; 522242692BFC7AFC0085C632 /* SideMenuVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideMenuVC.swift; sourceTree = ""; }; @@ -1714,6 +1716,7 @@ 52FDBA792BFF26F9009D7AC7 /* AuthFunc */ = { isa = PBXGroup; children = ( + 521E5A9C2CA1A5BE00AEF131 /* GoogleInterstistialADSetup.swift */, 9C27E1622BDB6F1900EC1DA9 /* AuthFunc.swift */, 525327D82BFCDDF700F64283 /* AuthFuncStartupSoundHandling.swift */, 52FDBA7A2BFF2712009D7AC7 /* AuthFuncTimeHandling.swift */, @@ -2533,6 +2536,7 @@ 525861D42C4FCCB500C33C79 /* CartPaymentOptionsVM.swift in Sources */, 52A3F6AF2BECC0690000BB0B /* LinkedChildVM.swift in Sources */, 9C85A9EC2C5CD5CD0031C365 /* MyListDataTemp.swift in Sources */, + 521E5A9D2CA1A5C800AEF131 /* GoogleInterstistialADSetup.swift in Sources */, 52A6DCB02C4E621800F63C51 /* BadgedBarButtonItem.swift in Sources */, 52C8EC7D2C3536E5002DC35C /* ContinueAudioCell.swift in Sources */, 525954252BE8F01600191286 /* ValueWrapper.swift in Sources */, diff --git a/WOKA/Audio Books/AudioBookHomeVC.swift b/WOKA/Audio Books/AudioBookHomeVC.swift index 8f25ca3..2851adc 100644 --- a/WOKA/Audio Books/AudioBookHomeVC.swift +++ b/WOKA/Audio Books/AudioBookHomeVC.swift @@ -76,7 +76,7 @@ class AudioBookHomeVC: UIViewController { */ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let audioBooksAd = adsData.result?.filter({$0.forPage == AdsEnum.audioBooks.rawValue}).first, let adID = audioBooksAd.id{ + if let audioBooksAd = adsData.result?.filter({$0.slug == AdsEnum.audioBooks.rawValue}).first, let adID = audioBooksAd.advertisement?.id{ PersistentStorage.shared.addAdsCount(adID: adID ,impressions: 1) } } @@ -99,7 +99,7 @@ class AudioBookHomeVC: UIViewController { */ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let audioBooksAd = adsData.result?.filter({$0.forPage == AdsEnum.audioBooks.rawValue}).first, let adLink = audioBooksAd.adLink, let adID = audioBooksAd.id{ + if let audioBooksAd = adsData.result?.filter({$0.slug == AdsEnum.audioBooks.rawValue}).first, let adLink = audioBooksAd.advertisement?.adLink, let adID = audioBooksAd.id{ PersistentStorage.shared.addAdsCount(adID: adID,clicks: 1) if let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url) @@ -221,7 +221,7 @@ extension AudioBookHomeVC : TableViewSRC{ /* MAke logic for ads */ - if let adsData = AuthFunc.shareInstance.adsData, adsData.result?.filter({$0.forPage == AdsEnum.audioBooks.rawValue}).first != nil{ + if let adsData = AuthFunc.shareInstance.adsData, let audioBooksAd = adsData.result?.filter({$0.slug == AdsEnum.audioBooks.rawValue}).first, (audioBooksAd.advertisement != nil || audioBooksAd.googleAd != nil){ // check if ads data contains ad for webseries }else{ /* @@ -274,7 +274,7 @@ extension AudioBookHomeVC : CollectionViewSRC{ /* MAke logic for ads */ - if let adsData = AuthFunc.shareInstance.adsData, adsData.result?.filter({$0.forPage == AdsEnum.karaoke.rawValue}).first != nil{ + if let adsData = AuthFunc.shareInstance.adsData, let audioBooksAd = adsData.result?.filter({$0.slug == AdsEnum.audioBooks.rawValue}).first, (audioBooksAd.advertisement != nil || audioBooksAd.googleAd != nil){ // check if ads data contains ad for webseries }else{ /* diff --git a/WOKA/Audio Books/AudioBookHomeVM.swift b/WOKA/Audio Books/AudioBookHomeVM.swift index a7863e4..872c308 100644 --- a/WOKA/Audio Books/AudioBookHomeVM.swift +++ b/WOKA/Audio Books/AudioBookHomeVM.swift @@ -38,24 +38,17 @@ class AudioBookHomeVM{ maxHeaderHeight = UIScreen.main.bounds.width * 0.55 vc.headerHeight.constant = maxHeaderHeight - DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: { [weak self] in - guard let self else{return} - checkAds() - }) + checkAds() } func checkAds(){ - - /* - This is test ad. - */ - + /* MAke logic for ads */ - if let adsData = AuthFunc.shareInstance.adsData, let audioBooksAd = adsData.result?.filter({$0.forPage == AdsEnum.audioBooks.rawValue}).first{ + if let adsData = AuthFunc.shareInstance.adsData, let audioBooksAd = adsData.result?.filter({$0.slug == AdsEnum.audioBooks.rawValue}).first{ // check if ads data contains ad for webseries - if let bannerImage = audioBooksAd.bannerImage, let buttonImage = audioBooksAd.buttonImage{ + if let bannerImage = audioBooksAd.advertisement?.bannerImage, let buttonImage = audioBooksAd.advertisement?.buttonImage{ vc.headerImage.imageURL(bannerImage, color: .white) vc.headerBtn.setTitle("", for: .normal) vc.headerTitleLabel.text = "" @@ -67,14 +60,17 @@ class AudioBookHomeVM{ if let adID = audioBooksAd.id{ PersistentStorage.shared.addAdsCount(adID: adID ,clicks: 1) } - if let adLink = audioBooksAd.adLink ,let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { + if let adLink = audioBooksAd.advertisement?.adLink ,let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url) } } + }else if audioBooksAd.googleAd != nil{ + DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: { [weak self] in + guard let self else{return} + AdReusable.sharedInstance.setupBannerAd(bannerView: headerBannerView, in:vc.headerView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc) + AdReusable.sharedInstance.setupBannerAd(bannerView: headerBannerBottomView, in: vc.listenView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc, height: 8, width: 15) + }) } - }else{ - AdReusable.sharedInstance.setupBannerAd(bannerView: headerBannerView, in:vc.headerView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc) - AdReusable.sharedInstance.setupBannerAd(bannerView: headerBannerBottomView, in: vc.listenView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc, height: 8, width: 15) } } @@ -193,30 +189,39 @@ class AudioBookHomeVM{ self.vc.tableHeight.constant = self.vc.audioListingTableView.contentSize.height + 100 self.vc.audioListingTableView.layoutIfNeeded() self.vc.tableHeight.constant = self.vc.audioListingTableView.contentSize.height + /* MAke logic for ads */ - if let adsData = AuthFunc.shareInstance.adsData{ - // check if ads data contains ad for webseries - if let audioBooksAd = adsData.result?.filter({$0.forPage == AdsEnum.audioBooks.rawValue}).first, let bannerImage = audioBooksAd.bannerImage, let buttonImage = audioBooksAd.buttonImage{ - vc.headerImage.imageURL(bannerImage, color: .white) - vc.headerBtn.setTitle("", for: .normal) - vc.headerTitleLabel.text = "" - vc.headerTitleHeight.constant = 10 - vc.headerBtn.backgroundColor = .clear - vc.headerBtn.sd_setBackgroundImage(with: URL(string:buttonImage), for: .normal) + if !isBtnClick{ // only load first time. + if let adsData = AuthFunc.shareInstance.adsData, let audioBooksAd = adsData.result?.filter({$0.slug == AdsEnum.audioBooks.rawValue}).first, (audioBooksAd.advertisement != nil || audioBooksAd.googleAd != nil){ + // this means ads are there }else{ - if !isBtnClick{ - self.headerData = self.audioListData.first - self.setHeaderData() - } - } - }else{ - if !isBtnClick{ - self.headerData = self.audioListData.first + self.headerData = data.first self.setHeaderData() } } +// if let adsData = AuthFunc.shareInstance.adsData{ +// // check if ads data contains ad for webseries +// if let audioBooksAd = adsData.result?.filter({$0.slug == AdsEnum.audioBooks.rawValue}).first, let bannerImage = audioBooksAd.advertisement?.bannerImage, let buttonImage = audioBooksAd.advertisement?.buttonImage{ +// vc.headerImage.imageURL(bannerImage, color: .white) +// vc.headerBtn.setTitle("", for: .normal) +// vc.headerTitleLabel.text = "" +// vc.headerTitleHeight.constant = 10 +// vc.headerBtn.backgroundColor = .clear +// vc.headerBtn.sd_setBackgroundImage(with: URL(string:buttonImage), for: .normal) +// }else{ +// if !isBtnClick{ +// self.headerData = self.audioListData.first +// self.setHeaderData() +// } +// } +// }else{ +// if !isBtnClick{ +// self.headerData = self.audioListData.first +// self.setHeaderData() +// } +// } self.stopShimmer() diff --git a/WOKA/Authentication/Controller/AppUpdateVC.swift b/WOKA/Authentication/Controller/AppUpdateVC.swift index 6a9435d..d0c385b 100644 --- a/WOKA/Authentication/Controller/AppUpdateVC.swift +++ b/WOKA/Authentication/Controller/AppUpdateVC.swift @@ -56,7 +56,9 @@ class AppUpdateVC: UIViewController { getUserData() }else{ //check if the static url data is fetched - UIApplication.setRootView(LoginNavVC.instantiate(from: .AuthenticationSB)) +// UIApplication.setRootView(LoginNavVC.instantiate(from: .AuthenticationSB)) + K.GVar.skippedUpdate = true + UIApplication.setRootView(MainNavController.instantiate(from: .Main)) } } } diff --git a/WOKA/Constants K/GVar.swift b/WOKA/Constants K/GVar.swift index 0e1cbf4..f8390df 100644 --- a/WOKA/Constants K/GVar.swift +++ b/WOKA/Constants K/GVar.swift @@ -41,5 +41,10 @@ extension K{ */ static var adTimeStamp : Date? = nil + /* + User Skipped update + */ + + static var skippedUpdate : Bool? = nil } } diff --git a/WOKA/Games/Controller/GamesDetailVC.swift b/WOKA/Games/Controller/GamesDetailVC.swift index 35f7f0d..06a94b2 100644 --- a/WOKA/Games/Controller/GamesDetailVC.swift +++ b/WOKA/Games/Controller/GamesDetailVC.swift @@ -37,16 +37,15 @@ class GamesDetailVC: UIViewController { var btnTapped : btnTappedBlock? var reloadType : FavCellCLick? - private var interstitial: GADInterstitialAd? - private var rewardedAd: GADRewardedAd? +// private var interstitial: GADInterstitialAd? +// private var rewardedAd: GADRewardedAd? - let reachability = NetworkReachabilityManager() override func viewDidLoad() { super.viewDidLoad() initView() tapHandler() - setupAds() + GoogleInterstistialADSetup.shareInstance.interstitial?.fullScreenContentDelegate = self } @objc func handleTap(_ gesture: UITapGestureRecognizer) { @@ -238,6 +237,19 @@ class GamesDetailVC: UIViewController { PersistentStorage.shared.addGamesCount(postID: postID) } + //If Google Interstitial is enable then only check for time and all, otherwise directly load GamesWebView + if let adsData = AuthFunc.shareInstance.adsData, let gamesInterstitialAd = adsData.result?.filter({$0.slug == AdsEnum.gameInterestial.rawValue}).first, gamesInterstitialAd.googleAd != nil{ + /* + Show google ads with dispatch queue. + */ + checkAds() + }else{ + K.GVar.adTimeStamp = nil + navigateToGamesWebView() + } + } + + func checkAds(){ /* check ad timestamp from gvar show ads if the saved timestamp time and current time has diffrenece of 30 minutes @@ -256,7 +268,7 @@ class GamesDetailVC: UIViewController { //show ads & reset timestamp to current time K.GVar.adTimeStamp = Date() - guard let interstitial = interstitial else { + guard let interstitial = GoogleInterstistialADSetup.shareInstance.interstitial else { // if ad doesnt loads make sure to make adtimestamp nil, and let user navigate to games K.GVar.adTimeStamp = nil navigateToGamesWebView() @@ -272,7 +284,7 @@ class GamesDetailVC: UIViewController { */ K.GVar.adTimeStamp = Date() - guard let interstitial = interstitial else { + guard let interstitial = GoogleInterstistialADSetup.shareInstance.interstitial else { // if ad doesnt loads make sure to make adtimestamp nil, and let user navigate to games K.GVar.adTimeStamp = nil navigateToGamesWebView() @@ -283,43 +295,26 @@ class GamesDetailVC: UIViewController { interstitial.present(fromRootViewController: nil) return } - } - private func setupAds(){ - GADInterstitialAd.load(withAdUnitID: K.GoogleAdIDs.gamesDetailsInterStial, request: GADRequest()) { [weak self] ad, error in - if let error = error { - print("Failed to load interstitial ad with error: \(error.localizedDescription)") - - // If internet is reachable, try to load the ad again - if self?.reachability?.isReachable == true { - self?.setupAds() - } - return - } - - // Successfully loaded the interstitial ad - self?.interstitial = ad - self?.interstitial?.fullScreenContentDelegate = self - print("Interstitial ad loaded successfully.") - } -// Task { -// do { -// interstitial = try await GADInterstitialAd.load( -// withAdUnitID: K.GoogleAdIDs.gamesDetailsInterStial, request: GADRequest()) -// -// GADInterstitialAd.load(withAdUnitID: K.GoogleAdIDs.gamesDetailsInterStial, request: GADRequest()) { ad, error in -// -// } -// interstitial?.fullScreenContentDelegate = self -// } catch { -// if reachability?.isReachable == true{ -// setupAds() -// } +// private func setupAds(){ +// GADInterstitialAd.load(withAdUnitID: K.GoogleAdIDs.gamesDetailsInterStial, request: GADRequest()) { [weak self] ad, error in +// if let error = error { // print("Failed to load interstitial ad with error: \(error.localizedDescription)") +// +// // If internet is reachable, try to load the ad again +// if self?.reachability?.isReachable == true { +// self?.setupAds() +// } +// return // } +// +// // Successfully loaded the interstitial ad +// self?.interstitial = ad +// self?.interstitial?.fullScreenContentDelegate = self +// print("Interstitial ad loaded successfully.") // } - } +// } private func navigateToGamesWebView(){ let sb = UIStoryboard(name: K.StoryBoard.Games, bundle: nil) @@ -361,6 +356,6 @@ extension GamesDetailVC : GADFullScreenContentDelegate{ print("Ad did dismiss full screen content.") self.navigateToGamesWebView() //setup ads again and wait for the timestamp 30 minutes - self.setupAds() + GoogleInterstistialADSetup.shareInstance.setupGoogleIntersitialAD() } } diff --git a/WOKA/Games/Controller/GamesListVC.swift b/WOKA/Games/Controller/GamesListVC.swift index 7e0da03..762cf4b 100644 --- a/WOKA/Games/Controller/GamesListVC.swift +++ b/WOKA/Games/Controller/GamesListVC.swift @@ -67,7 +67,7 @@ class GamesListVC: UIViewController { */ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let gamesAd = adsData.result?.filter({$0.forPage == AdsEnum.games.rawValue}).first, let adID = gamesAd.id{ + if let gamesAd = adsData.result?.filter({$0.slug == AdsEnum.games.rawValue}).first, let adID = gamesAd.id{ PersistentStorage.shared.addAdsCount(adID: adID ,impressions: 1) } } @@ -86,7 +86,7 @@ class GamesListVC: UIViewController { */ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let gamesAd = adsData.result?.filter({$0.forPage == AdsEnum.games.rawValue}).first, let adLink = gamesAd.adLink, let adID = gamesAd.id{ + if let gamesAd = adsData.result?.filter({$0.slug == AdsEnum.games.rawValue}).first, let adLink = gamesAd.advertisement?.adLink, let adID = gamesAd.id{ PersistentStorage.shared.addAdsCount(adID: adID,clicks: 1) if let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url) @@ -163,7 +163,7 @@ extension GamesListVC : TableViewSRC{ /* MAke logic for ads */ - if let adsData = AuthFunc.shareInstance.adsData, adsData.result?.filter({$0.forPage == AdsEnum.games.rawValue}).first != nil{ + if let adsData = AuthFunc.shareInstance.adsData, let gamesAd = adsData.result?.filter({$0.slug == AdsEnum.games.rawValue}).first, (gamesAd.advertisement != nil || gamesAd.googleAd != nil){ // check if ads data contains ad for webseries }else{ vm.setHeaderData() @@ -190,6 +190,7 @@ extension GamesListVC : TableViewSRC{ extension GamesListVC : ReloadSeriesFavLike{ func updateRows(index: Int, type: FavCellCLick, isFav: Bool?, isLike: Bool?, id: Int?) { + if let isFav{ switch isFav{ case true: diff --git a/WOKA/Games/Controller/GamesWebViewVC.swift b/WOKA/Games/Controller/GamesWebViewVC.swift index 25c125b..2dcc09d 100644 --- a/WOKA/Games/Controller/GamesWebViewVC.swift +++ b/WOKA/Games/Controller/GamesWebViewVC.swift @@ -128,10 +128,16 @@ class GamesWebViewVC: UIViewController, WKNavigationDelegate,UIGestureRecognizer // MARK: - SetupAds private func showAds(){ - DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: {[weak self] in - guard let self else{return} - AdReusable.sharedInstance.setupBannerAd(bannerView: self.bottomBannerView, in: adView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self) - }) + if let adsData = AuthFunc.shareInstance.adsData, let gamesWebViewAd = adsData.result?.filter({$0.slug == AdsEnum.gameWebView.rawValue}).first, gamesWebViewAd.googleAd != nil{ + /* + Show google ads with dispatch queue. + */ + DispatchQueue.main.asyncAfter(deadline: .now() + 0.8, execute: { [weak self] in + guard let self else{return} + AdReusable.sharedInstance.setupBannerAd(bannerView: self.bottomBannerView, in: adView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self) + }) + } + } diff --git a/WOKA/Games/ViewModel/GamesListVM.swift b/WOKA/Games/ViewModel/GamesListVM.swift index 5e06045..12ed894 100644 --- a/WOKA/Games/ViewModel/GamesListVM.swift +++ b/WOKA/Games/ViewModel/GamesListVM.swift @@ -32,11 +32,8 @@ class GamesListVM{ //Set banner height maxHeaderHeight = UIScreen.main.bounds.width * 0.55 vc.headerHeight.constant = maxHeaderHeight - - DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: { [weak self] in - guard let self else{return} - checkAds() - }) + + checkAds() } func checkAds(){ @@ -48,9 +45,9 @@ class GamesListVM{ /* MAke logic for ads */ - if let adsData = AuthFunc.shareInstance.adsData, let gamesAd = adsData.result?.filter({$0.forPage == AdsEnum.games.rawValue}).first{ + if let adsData = AuthFunc.shareInstance.adsData, let gamesAd = adsData.result?.filter({$0.slug == AdsEnum.games.rawValue}).first{ // check if ads data contains ad for webseries - if let bannerImage = gamesAd.bannerImage, let buttonImage = gamesAd.buttonImage{ + if let bannerImage = gamesAd.advertisement?.bannerImage, let buttonImage = gamesAd.advertisement?.buttonImage{ vc.headerImage.imageURL(bannerImage, color: .white) vc.headerBtn.setTitle("", for: .normal) vc.headerTitleLabel.text = "" @@ -62,14 +59,17 @@ class GamesListVM{ if let adID = gamesAd.id{ PersistentStorage.shared.addAdsCount(adID: adID ,clicks: 1) } - if let adLink = gamesAd.adLink ,let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { + if let adLink = gamesAd.advertisement?.adLink ,let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url) } } + }else if gamesAd.googleAd != nil{ + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: { [weak self] in + guard let self else{return} + AdReusable.sharedInstance.setupBannerAd(bannerView: headerBannerView, in:vc.headerView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc) + AdReusable.sharedInstance.setupBannerAd(bannerView: headerBannerBottomView, in: vc.gamesLoadingView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc, height: 8, width: 15) + }) } - }else{ - AdReusable.sharedInstance.setupBannerAd(bannerView: headerBannerView, in:vc.headerView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc) - AdReusable.sharedInstance.setupBannerAd(bannerView: headerBannerBottomView, in: vc.gamesLoadingView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc, height: 8, width: 15) } } @@ -149,7 +149,7 @@ class GamesListVM{ */ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let gamesAd = adsData.result?.filter({$0.forPage == AdsEnum.games.rawValue}).first, let bannerImage = gamesAd.bannerImage, let buttonImage = gamesAd.buttonImage{ + if let gamesAd = adsData.result?.filter({$0.slug == AdsEnum.games.rawValue}).first, let bannerImage = gamesAd.advertisement?.bannerImage, let buttonImage = gamesAd.advertisement?.buttonImage{ vc.headerImage.imageURL(bannerImage, color: .white) vc.headerBtn.setTitle("", for: .normal) vc.headerTitleLabel.text = "" diff --git a/WOKA/Home/Controller/HomeVC.swift b/WOKA/Home/Controller/HomeVC.swift index b5da6f6..98a2176 100644 --- a/WOKA/Home/Controller/HomeVC.swift +++ b/WOKA/Home/Controller/HomeVC.swift @@ -18,7 +18,14 @@ class HomeVC: UIViewController ,ChildViewControllerDelegate{ override func viewDidLoad() { super.viewDidLoad() - + //setup google ads for fullscreen if its turned on. + if let adsData = AuthFunc.shareInstance.adsData, let gamesIntersitialAd = adsData.result?.filter({$0.slug == AdsEnum.gameInterestial.rawValue}).first, gamesIntersitialAd.googleAd != nil{ + /* + setup google ads. + */ + GoogleInterstistialADSetup.shareInstance.setupGoogleIntersitialAD() + } + switch AuthFunc.shareInstance.selectedTheme { case .theme1: let sb = UIStoryboard(name: K.StoryBoard.theme, bundle: nil) diff --git a/WOKA/Home/ViewModel/MyListVM.swift b/WOKA/Home/ViewModel/MyListVM.swift index 6950114..b5d5962 100644 --- a/WOKA/Home/ViewModel/MyListVM.swift +++ b/WOKA/Home/ViewModel/MyListVM.swift @@ -52,7 +52,6 @@ class MyListVM{ DispatchQueue.main.async { self.vc.shimmerView.forEach { shimmer in if load{ - shimmer.gradientColorOne = #colorLiteral(red: 0.1210066287, green: 0.8382952364, blue: 0.9853085876, alpha: 1) shimmer.startShimmer() }else{ shimmer.stopShimmer() diff --git a/WOKA/Karaoke/Controller/KaraokeListingVC.swift b/WOKA/Karaoke/Controller/KaraokeListingVC.swift index 358482a..9161aa5 100644 --- a/WOKA/Karaoke/Controller/KaraokeListingVC.swift +++ b/WOKA/Karaoke/Controller/KaraokeListingVC.swift @@ -79,7 +79,7 @@ class KaraokeListingVC: UIViewController { */ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let karaokeAd = adsData.result?.filter({$0.forPage == AdsEnum.karaoke.rawValue}).first, let adID = karaokeAd.id{ + if let karaokeAd = adsData.result?.filter({$0.slug == AdsEnum.karaoke.rawValue}).first, let adID = karaokeAd.advertisement?.id{ PersistentStorage.shared.addAdsCount(adID: adID ,impressions: 1) } } @@ -100,7 +100,7 @@ class KaraokeListingVC: UIViewController { */ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let karaokeAd = adsData.result?.filter({$0.forPage == AdsEnum.karaoke.rawValue}).first, let adLink = karaokeAd.adLink, let adID = karaokeAd.id{ + if let karaokeAd = adsData.result?.filter({$0.slug == AdsEnum.karaoke.rawValue}).first, let adLink = karaokeAd.advertisement?.adLink, let adID = karaokeAd.advertisement?.id{ PersistentStorage.shared.addAdsCount(adID: adID ,clicks: 1) if let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { @@ -175,16 +175,16 @@ extension KaraokeListingVC : CollectionViewSRC{ /* MAke logic for ads */ - if let adsData = AuthFunc.shareInstance.adsData, adsData.result?.filter({$0.forPage == AdsEnum.karaoke.rawValue}).first != nil{ + if let adsData = AuthFunc.shareInstance.adsData, let karaokeAd = adsData.result?.filter({$0.slug == AdsEnum.karaoke.rawValue}).first, (karaokeAd.advertisement != nil || karaokeAd.googleAd != nil){ // check if ads data contains ad for webseries }else{ /* Updated the top header data */ - vm.headerData = data - vm.setHeaderData() + vm.updateHeaderData(data: data) } + let sb = UIStoryboard(name: K.StoryBoard.Karaoke, bundle: nil) let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Karaoke.karaokeDetailsVC) as! KaraokeDetailsVC vcPush.modalPresentationStyle = .overCurrentContext @@ -194,7 +194,6 @@ extension KaraokeListingVC : CollectionViewSRC{ self.present(vcPush, animated: true) } - } // MARK: - Collection Flow Layout @@ -265,14 +264,13 @@ extension KaraokeListingVC : TableViewSRC{ /* MAke logic for ads */ - if let adsData = AuthFunc.shareInstance.adsData, adsData.result?.filter({$0.forPage == AdsEnum.karaoke.rawValue}).first != nil{ + if let adsData = AuthFunc.shareInstance.adsData, let karaokeAd = adsData.result?.filter({$0.slug == AdsEnum.karaoke.rawValue}).first, (karaokeAd.advertisement != nil || karaokeAd.googleAd != nil){ // check if ads data contains ad for webseries }else{ /* Updated the top header data */ - vm.headerData = data - vm.setHeaderData() + vm.updateHeaderData(data: data) } let sb = UIStoryboard(name: K.StoryBoard.Karaoke, bundle: nil) diff --git a/WOKA/Karaoke/ViewModel/JWKaraokePlayerVM.swift b/WOKA/Karaoke/ViewModel/JWKaraokePlayerVM.swift index a5fc155..444fc1d 100644 --- a/WOKA/Karaoke/ViewModel/JWKaraokePlayerVM.swift +++ b/WOKA/Karaoke/ViewModel/JWKaraokePlayerVM.swift @@ -31,10 +31,15 @@ class JWKaraokePlayerVM{ var headerBannerView = GADBannerView() func initView(){ - DispatchQueue.main.asyncAfter(deadline: .now() + 0.8, execute: { [weak self] in - guard let self else{return} - AdReusable.sharedInstance.setupBannerAd(bannerView: self.headerBannerView, in: vc.adView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc) - }) + if let adsData = AuthFunc.shareInstance.adsData, let karaokePlayerAd = adsData.result?.filter({$0.slug == AdsEnum.karaokePlayer.rawValue}).first, karaokePlayerAd.googleAd != nil{ + /* + Show google ads with dispatch queue. + */ + DispatchQueue.main.asyncAfter(deadline: .now() + 0.8, execute: { [weak self] in + guard let self else{return} + AdReusable.sharedInstance.setupBannerAd(bannerView: self.headerBannerView, in: vc.adView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc) + }) + } startTimeStamp = Date() vc.downloadRecordingBtn.isEnabled = false diff --git a/WOKA/Karaoke/ViewModel/KaraokeListingVM.swift b/WOKA/Karaoke/ViewModel/KaraokeListingVM.swift index 73f6507..741bf05 100644 --- a/WOKA/Karaoke/ViewModel/KaraokeListingVM.swift +++ b/WOKA/Karaoke/ViewModel/KaraokeListingVM.swift @@ -38,10 +38,7 @@ class KaraokeListingVM{ maxHeaderHeight = UIScreen.main.bounds.width * 0.55 vc.headerHeight.constant = maxHeaderHeight - DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: { [weak self] in - guard let self else{return} - checkAds() - }) + checkAds() } func setupCell(){ @@ -61,6 +58,7 @@ class KaraokeListingVM{ } func setHeaderData(){ + guard let data = self.headerData else{return} if let url = data.thumbnailPath{ @@ -85,9 +83,9 @@ class KaraokeListingVM{ /* MAke logic for ads */ - if let adsData = AuthFunc.shareInstance.adsData, let webSeriesAd = adsData.result?.filter({$0.forPage == AdsEnum.karaoke.rawValue}).first{ + if let adsData = AuthFunc.shareInstance.adsData, let karaokeAd = adsData.result?.filter({$0.slug == AdsEnum.karaoke.rawValue}).first{ // check if ads data contains ad for webseries - if let bannerImage = webSeriesAd.bannerImage, let buttonImage = webSeriesAd.buttonImage{ + if let bannerImage = karaokeAd.advertisement?.bannerImage, let buttonImage = karaokeAd.advertisement?.buttonImage{ vc.headerImage.imageURL(bannerImage, color: .white) vc.headerBtn.setTitle("", for: .normal) vc.headerTitleLabel.text = "" @@ -96,20 +94,25 @@ class KaraokeListingVM{ vc.headerBtn.sd_setBackgroundImage(with: URL(string:buttonImage), for: .normal) vc.headerImage.addTapGesture { - if let adID = webSeriesAd.id{ + if let adID = karaokeAd.advertisement?.id{ PersistentStorage.shared.addAdsCount(adID: adID ,clicks: 1) } - if let adLink = webSeriesAd.adLink ,let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { + if let adLink = karaokeAd.advertisement?.adLink ,let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url) } } + }else if karaokeAd.googleAd != nil{ + DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: { [weak self] in + guard let self else{return} + AdReusable.sharedInstance.setupBannerAd(bannerView: self.headerBannerView, in: vc.headerView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc) + AdReusable.sharedInstance.setupBannerAd(bannerView: self.headerBannerBottomView, in: vc.selectedShowView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc, height: 8, width: 15) + }) } - }else{ - AdReusable.sharedInstance.setupBannerAd(bannerView: self.headerBannerView, in: vc.headerView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc) - AdReusable.sharedInstance.setupBannerAd(bannerView: self.headerBannerBottomView, in: vc.selectedShowView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc, height: 8, width: 15) } } + + // MARK: - GetKaraoke Listing func getContinueWatching(){ @@ -184,34 +187,18 @@ class KaraokeListingVM{ self.vc.tableHeight.constant = self.vc.karaokeListingTableView.contentSize.height + 100 self.vc.karaokeListingTableView.layoutIfNeeded() self.vc.tableHeight.constant = self.vc.karaokeListingTableView.contentSize.height + 10 - - /* - MAke logic for ads - */ -// if let adsData = AuthFunc.shareInstance.adsData{ -// // check if ads data contains ad for webseries -// if let karaokeAd = adsData.result?.filter({$0.forPage == AdsEnum.karaoke.rawValue}).first, let bannerImage = karaokeAd.bannerImage, let buttonImage = karaokeAd.buttonImage{ -// vc.headerImage.imageURL(bannerImage, color: .white) -// vc.headerBtn.setTitle("", for: .normal) -// vc.headerTitleLabel.text = "" -// vc.headerViewLabelHeight.constant = 10 -// vc.headerBtn.backgroundColor = .clear -// vc.headerBtn.sd_setBackgroundImage(with: URL(string:buttonImage), for: .normal) -// }else{ -// if !isBtnClick{ -// self.headerData = self.karaokeListData.first -// setHeaderData() -// } -// } -// }else{ -// if !isBtnClick{ -// self.headerData = self.karaokeListData.first -// setHeaderData() -// } -// } - self.stopShimmer() + if !isBtnClick{ // only load first time. + if let adsData = AuthFunc.shareInstance.adsData, let karaokeAd = adsData.result?.filter({$0.slug == AdsEnum.karaoke.rawValue}).first, (karaokeAd.advertisement != nil || karaokeAd.googleAd != nil){ + // this means ads are there + }else{ + self.headerData = data.first + self.setHeaderData() + } + } + + self.vc.loadMoreActivityIndicator.stopAnimating() self.vc.loadMoreActivityIndicator.hidesWhenStopped = true @@ -244,6 +231,11 @@ class KaraokeListingVM{ self.vc.selectedShowView.stopShimmer() } + func updateHeaderData(data : KaraokeListingDM.KaraokeDatum){ + headerData = data + setHeaderData() + } + // MARK: - Update Fav Likes func updateFavLikes(type : FavCellCLick, isFav : Bool? ,isLiked : Bool?, postID : Int , postType : Int){ diff --git a/WOKA/Main/AuthFunc/AdsDM.swift b/WOKA/Main/AuthFunc/AdsDM.swift index b52e172..2b9908c 100644 --- a/WOKA/Main/AuthFunc/AdsDM.swift +++ b/WOKA/Main/AuthFunc/AdsDM.swift @@ -9,7 +9,7 @@ import Foundation // MARK: - AdsDM struct AdsDM: Codable { - let result: [ResultData]? + let result: [Result]? let totalRecords: Int? enum CodingKeys: String, CodingKey { @@ -18,20 +18,83 @@ struct AdsDM: Codable { } // MARK: - Result - struct ResultData: Codable { + struct Result: Codable { let id: Int? + let pageName, slug, isActive: String? + let advertisement: Advertisement? + let googleAd: GoogleAd? + + enum CodingKeys: String, CodingKey { + case id + case pageName = "page_name" + case slug + case isActive = "is_active" + case advertisement + case googleAd = "google_ad" + } + } + + // MARK: - Advertisement + struct Advertisement: Codable { + let id, adPagesXid: Int? let title, adCompany: String? let bannerImage, buttonImage: String? let forPage: String? let adLink: String? + let isActive: String? enum CodingKeys: String, CodingKey { - case id, title + case id + case adPagesXid = "ad_pages_xid" + case title case adCompany = "ad_company" case bannerImage = "banner_image" case buttonImage = "button_image" case forPage = "for_page" case adLink = "ad_link" + case isActive = "is_active" + } + } + + // MARK: - GoogleAd + struct GoogleAd: Codable { + let id, adPagesXid: Int? + let isActive: String? + + enum CodingKeys: String, CodingKey { + case id + case adPagesXid = "ad_pages_xid" + case isActive = "is_active" } } } + + +//// MARK: - AdsDM +//struct AdsDM: Codable { +// let result: [ResultData]? +// let totalRecords: Int? +// +// enum CodingKeys: String, CodingKey { +// case result +// case totalRecords = "total_records" +// } +// +// // MARK: - Result +// struct ResultData: Codable { +// let id: Int? +// let title, adCompany: String? +// let bannerImage, buttonImage: String? +// let forPage: String? +// let adLink: String? +// +// enum CodingKeys: String, CodingKey { +// case id, title +// case adCompany = "ad_company" +// case bannerImage = "banner_image" +// case buttonImage = "button_image" +// case forPage = "for_page" +// case adLink = "ad_link" +// } +// } +//} diff --git a/WOKA/Main/AuthFunc/AuthFunc.swift b/WOKA/Main/AuthFunc/AuthFunc.swift index e5b85f6..36ff7fc 100644 --- a/WOKA/Main/AuthFunc/AuthFunc.swift +++ b/WOKA/Main/AuthFunc/AuthFunc.swift @@ -22,8 +22,12 @@ enum AdsEnum : String{ case shop_super_category = "shop-super-category" case web_series = "web-series" case karaoke = "karaoke" + case karaokePlayer = "karaoke-player" case audioBooks = "audio-books" case games = "games" + case gameWebView = "game-web-view" + case gameInterestial = "game-interestial" + case fm = "fm" } class AuthFunc{ @@ -231,7 +235,7 @@ class AuthFunc{ func getAds(onCompletion: ((Bool) -> Void)? = nil){ let params : Parameters = ["start" : "0", - "limit":"0"] + "limit":"20"] NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Analytics.get_ad_data, method: .get,parameters: params) { (result : Result, NetworkManager.APIError>) in switch result{ case .success(let data): diff --git a/WOKA/Main/AuthFunc/GoogleInterstistialADSetup.swift b/WOKA/Main/AuthFunc/GoogleInterstistialADSetup.swift new file mode 100644 index 0000000..4da09ea --- /dev/null +++ b/WOKA/Main/AuthFunc/GoogleInterstistialADSetup.swift @@ -0,0 +1,36 @@ +// +// GoogleInterstistialADSetup.swift +// WOKA +// +// Created by MacBook Pro on 23/09/24. +// + +import GoogleMobileAds +import Alamofire + +class GoogleInterstistialADSetup{ + + static let shareInstance = GoogleInterstistialADSetup() + let reachability = NetworkReachabilityManager() + + private init(){} + var interstitial: GADInterstitialAd? + + func setupGoogleIntersitialAD(){ + GADInterstitialAd.load(withAdUnitID: K.GoogleAdIDs.gamesDetailsInterStial, request: GADRequest()) { [weak self] ad, error in + if let error = error { + print("Failed to load interstitial ad with error: \(error.localizedDescription)") + + // If internet is reachable, try to load the ad again + if self?.reachability?.isReachable == true { + self?.setupGoogleIntersitialAD() + } + return + } + + // Successfully loaded the interstitial ad + self?.interstitial = ad + print("Interstitial ad loaded successfully.") + } + } +} diff --git a/WOKA/Main/Delegate/UIApplicationSwitchRoot.swift b/WOKA/Main/Delegate/UIApplicationSwitchRoot.swift index ff1d0a5..2e6584d 100644 --- a/WOKA/Main/Delegate/UIApplicationSwitchRoot.swift +++ b/WOKA/Main/Delegate/UIApplicationSwitchRoot.swift @@ -63,6 +63,7 @@ enum AppStoryboard: String { case Main = "Main" case Home = "Home" case AuthenticationSB = "AuthenticationSB" + // Computed property that returns an instance of UIStoryboard for the given case. var instance: UIStoryboard { // Creates and returns a UIStoryboard instance with the name of the enum case and the main bundle. diff --git a/WOKA/Network Adapter/APIEndPoints.swift b/WOKA/Network Adapter/APIEndPoints.swift index e958fd0..b632c60 100644 --- a/WOKA/Network Adapter/APIEndPoints.swift +++ b/WOKA/Network Adapter/APIEndPoints.swift @@ -156,7 +156,7 @@ struct APIEndPoints { struct Analytics{ static let user_clicks = makeURL(path: "v2/user_clicks") static let user_video_view = makeURL(path: "user_video_view") - static let get_ad_data = makeURL(path: "get_ad_data") + static let get_ad_data = makeURL(path: "v2/get_ad_data") static let update_ad_count = makeURL(path: "update_ad_count") } diff --git a/WOKA/OnBoarding Module/Controller/SplashVC.swift b/WOKA/OnBoarding Module/Controller/SplashVC.swift index 8aa144c..9630a0a 100644 --- a/WOKA/OnBoarding Module/Controller/SplashVC.swift +++ b/WOKA/OnBoarding Module/Controller/SplashVC.swift @@ -33,19 +33,28 @@ class SplashVC: UIViewController { /* Show google ads with dispatch queue. */ - DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: { [weak self] in + DispatchQueue.main.asyncAfter(deadline: .now(), execute: { [weak self] in guard let self else{return} AdReusable.sharedInstance.setupBannerAd(bannerView: vm.banner1, in: adBanner1, adUnitID: K.GoogleAdIDs.splashBanner1, viewController: self) AdReusable.sharedInstance.setupBannerAd(bannerView: vm.banner2, in: adBanner2, adUnitID: K.GoogleAdIDs.splashBanner2, viewController: self) + vm.initView() + }) - + self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.plain, target:nil, action:nil) vm.vc = self + print("OneSignalID:- ", OneSignal.User.pushSubscription.id ?? "NIL") + + if K.GVar.skippedUpdate == true{ + K.GVar.skippedUpdate = nil + self.languageBtnStack.isHidden = false + self.wokaLogo.transform = CGAffineTransform(scaleX: 1.8, y: 1.8) + return + } + vm.playSplashSound() animateImageScale() - self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.plain, target:nil, action:nil) - print("OneSignalID:- ", OneSignal.User.pushSubscription.id ?? "NIL") } @IBAction func languageBtnTapped(_ sender: UIButton) { @@ -138,6 +147,7 @@ class SplashVC: UIViewController { AuthFunc.shareInstance.getStaticURLs() } } + UIView.animate(withDuration: 0.5, animations: { [weak self] in guard let self else{return} // Update the constant value of the top constraint @@ -146,6 +156,7 @@ class SplashVC: UIViewController { self.view.layoutIfNeeded() }) { _ in if !AuthFunc.shareInstance.checkLogin(){ + self.vm.startStopIndicator(start: false,hide: true) UIView.animate(withDuration: 0.3, delay: 0,options : [.transitionCrossDissolve],animations: { // Set the isHidden property of the view self.languageBtnStack.isHidden = false @@ -158,7 +169,6 @@ class SplashVC: UIViewController { } override func viewDidLayoutSubviews() { - vm.initView() } } diff --git a/WOKA/PersistentStorage.swift b/WOKA/PersistentStorage.swift index aa3c12b..a1bfa6d 100644 --- a/WOKA/PersistentStorage.swift +++ b/WOKA/PersistentStorage.swift @@ -223,25 +223,8 @@ final class PersistentStorage debugPrint(error) } } - - func getAllData() { - //We need to create a context from this container - let managedContext = PersistentStorage.shared.context - let fetchRequest:NSFetchRequest = NSFetchRequest.init(entityName: "UserClicks") - fetchRequest.fetchLimit = 10 - do { - guard let result = try managedContext.fetch(fetchRequest) as? [UserClicks] else {return} - result.forEach { clicks in - // device type 1- android , 2 - iOS - print("ID:-" , PostType(rawValue: Int(clicks.post_type))!, "CatID:- ", clicks.category_id, "PostID:- ", clicks.post_id , "Count:-", clicks.click_counts) - } - } - catch let error - { - debugPrint(error) - } - } - + + //Sending Clicks data to our server func sendDataToServer() { //We need to create a context from this container @@ -254,14 +237,25 @@ final class PersistentStorage do { guard let result = try managedContext.fetch(fetchRequest) as? [UserClicks] else {return} var userClicks = [ClicksAnalytics]() + + print("UserClicks Count from SendData to server :- ", result.count) + + //if data is less , dont keep sending the data to server + if result.count < 5 { + print("Not Enough Data") + return + } + result.forEach { clicks in // device type 1- android , 2 - iOS userClicks.append(ClicksAnalytics(postID: Int(clicks.post_id), postType: Int(clicks.post_type), numberOfClicks: Int(clicks.click_counts), deviceType: 2, categoryID: Int(clicks.category_id))) print("ID:-" , PostType(rawValue: Int(clicks.post_type))!, "CatID:- ", clicks.category_id, "PostID:- ", clicks.post_id , "Count:-", clicks.click_counts) } + + // send data to server NetworkManager.shareInstance.nwCallRawJSON(clicksData: userClicks) { isDone in - if isDone{ + if isDone{ // if data is send to server and we get success callback then delete that data from coredata entity. self.deleteData(result) } } @@ -272,6 +266,7 @@ final class PersistentStorage } } + //Delete data from CoreData func deleteData(_ data: [UserClicks]) { let managedContext = PersistentStorage.shared.context @@ -281,6 +276,8 @@ final class PersistentStorage do { try managedContext.save() + + //after deleting check if more data exist. getAllData() print("Deleted data") } catch let error { @@ -288,7 +285,36 @@ final class PersistentStorage } } - + //Get all data from DB + func getAllData() { + //We need to create a context from this container + let managedContext = PersistentStorage.shared.context + let fetchRequest:NSFetchRequest = NSFetchRequest.init(entityName: "UserClicks") + fetchRequest.fetchLimit = 15 + do { + guard let result = try managedContext.fetch(fetchRequest) as? [UserClicks] else {return} + + print("UserClicks Count from getAllData :- ", result.count) + //if data is less , dont keep sending the data to server + if result.count < 5 { + print("Not Enough Data") + return + } else{ + // send data again to server + sendDataToServer() + print("Data sent Again.") + } + + result.forEach { clicks in + // device type 1- android , 2 - iOS + print("ID:-" , PostType(rawValue: Int(clicks.post_type))!, "CatID:- ", clicks.category_id, "PostID:- ", clicks.post_id , "Count:-", clicks.click_counts) + } + } + catch let error + { + debugPrint(error) + } + } // MARK: - Handle Clicks For UserClicks @@ -348,13 +374,24 @@ final class PersistentStorage fetchRequest.fetchLimit = 15 do { guard let result = try managedContext.fetch(fetchRequest) as? [AdClicksImpressions] else {return} + + print("userImpressions Count from SendAdsData to server :- ", result.count) + + //if data is less , dont keep sending the data to server + if result.count < 2 { + print("Not Enough Data") + return + } + var userImpressions = [AdsClickImpressionsData]() + result.forEach { ads in // device type 1- android , 2 - iOS userImpressions.append(AdsClickImpressionsData(adID: Int(ads.ad_id), noOfClick: Int(ads.no_of_click), noOfOmpression: Int(ads.no_of_impression))) print("ID:-" , ads.ad_id, "No Of Clicks :- ", ads.no_of_click, "Impressions :- ", ads.no_of_impression) } + NetworkManager.shareInstance.nwCallRawJSONAds(adsData: userImpressions) { isDone in if isDone{ self.deleteAdsData(result) @@ -448,10 +485,40 @@ final class PersistentStorage do { try managedContext.save() - getAllData() + getAllAdsData() print("Deleted data") } catch let error { debugPrint("Failed to delete data:", error) } } + + func getAllAdsData() { + //We need to create a context from this container + let managedContext = PersistentStorage.shared.context + let fetchRequest:NSFetchRequest = NSFetchRequest.init(entityName: "AdClicksImpressions") +// fetchRequest.fetchLimit = 2 + do { + guard let result = try managedContext.fetch(fetchRequest) as? [AdClicksImpressions] else {return} + + print("UserClicks Count from getAllData :- ", result.count) + //if data is less , dont keep sending the data to server + if result.count < 2 { + print("Not Enough Ads Data") + return + } else{ + // send ads data again to server + sendAdsData() + print("Ads Data sent Again.") + } + +// result.forEach { clicks in +// // device type 1- android , 2 - iOS +// print("ID:-" , PostType(rawValue: Int(clicks.post_type))!, "CatID:- ", clicks.category_id, "PostID:- ", clicks.post_id , "Count:-", clicks.click_counts) +// } + } + catch let error + { + debugPrint(error) + } + } } diff --git a/WOKA/Shop/Controller/ShopListingVC.swift b/WOKA/Shop/Controller/ShopListingVC.swift index 91ff8da..ce854c3 100644 --- a/WOKA/Shop/Controller/ShopListingVC.swift +++ b/WOKA/Shop/Controller/ShopListingVC.swift @@ -20,7 +20,6 @@ class ShopListingVC: UIViewController { vm.initView() navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) navigationController?.navigationBar.shadowImage = UIImage() - } override func viewWillAppear(_ animated: Bool) { @@ -56,7 +55,7 @@ class ShopListingVC: UIViewController { */ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let shopSuperCatAd = adsData.result?.filter({$0.forPage == AdsEnum.shop_super_category.rawValue}).first, let adID = shopSuperCatAd.id{ + if let shopSuperCatAd = adsData.result?.filter({$0.slug == AdsEnum.shop_super_category.rawValue}).first, let adID = shopSuperCatAd.id{ PersistentStorage.shared.addAdsCount(adID: adID ,impressions: 1) } } @@ -96,7 +95,7 @@ extension ShopListingVC : TableViewSRC{ if vm.superCatData[indexPath.row].isAD == true{ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let shopSuperCatAd = adsData.result?.filter({$0.forPage == AdsEnum.shop_super_category.rawValue}).first,let adLink = shopSuperCatAd.adLink, let adID = shopSuperCatAd.id{ + if let shopSuperCatAd = adsData.result?.filter({$0.slug == AdsEnum.shop_super_category.rawValue}).first,let adLink = shopSuperCatAd.advertisement?.adLink, let adID = shopSuperCatAd.id{ PersistentStorage.shared.addAdsCount(adID: adID,clicks: 1) if let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url) diff --git a/WOKA/Shop/ViewModel/ShopListingVM.swift b/WOKA/Shop/ViewModel/ShopListingVM.swift index 2c81687..aae2b60 100644 --- a/WOKA/Shop/ViewModel/ShopListingVM.swift +++ b/WOKA/Shop/ViewModel/ShopListingVM.swift @@ -85,12 +85,14 @@ class ShopListingVM{ vc.tableView.isHidden = false /* - MAke logic for ads + If ads found then only load it or else directly append the data and reload */ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let shopSuperCatAd = adsData.result?.filter({$0.forPage == AdsEnum.shop_super_category.rawValue}).first, let bannerImage = shopSuperCatAd.bannerImage{ - self.superCatData.append(ShopSuperCategoryDM.ResultData(id: shopSuperCatAd.id, superCategoryName: shopSuperCatAd.title, superCategoryThumbnail: bannerImage,isAD: true)) + if let shopSuperCatAd = adsData.result?.filter({$0.slug == AdsEnum.shop_super_category.rawValue}).first, let bannerImage = shopSuperCatAd.advertisement?.bannerImage{ + self.superCatData.append(ShopSuperCategoryDM.ResultData(id: shopSuperCatAd.id, superCategoryName: shopSuperCatAd.advertisement?.title, superCategoryThumbnail: bannerImage,isAD: true)) + }else{ // check if google ads + } } diff --git a/WOKA/Theme/Controller/ThemeOneVC.swift b/WOKA/Theme/Controller/ThemeOneVC.swift index d6742e1..6011b6f 100644 --- a/WOKA/Theme/Controller/ThemeOneVC.swift +++ b/WOKA/Theme/Controller/ThemeOneVC.swift @@ -98,6 +98,7 @@ class ThemeOneVC: UIViewController { } override func viewDidAppear(_ animated: Bool) { + AuthFunc.shareInstance.getAds() K.GVar.topView = .theme1 vm.shouldAnimate = true @@ -107,7 +108,6 @@ class ThemeOneVC: UIViewController { vm.moveCloudView() } if let player = vm.avPlayer{ - player.status player.play() } @@ -116,7 +116,7 @@ class ThemeOneVC: UIViewController { */ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let themeOneAd = adsData.result?.filter({$0.forPage == AdsEnum.themeOne.rawValue}).first, let adID = themeOneAd.id{ + if let themeOneAd = adsData.result?.filter({$0.slug == AdsEnum.themeOne.rawValue}).first, let adID = themeOneAd.id{ PersistentStorage.shared.addAdsCount(adID: adID ,impressions: 1) } } diff --git a/WOKA/Theme/ViewModel/ThemeOneVM.swift b/WOKA/Theme/ViewModel/ThemeOneVM.swift index c2bca72..e289493 100644 --- a/WOKA/Theme/ViewModel/ThemeOneVM.swift +++ b/WOKA/Theme/ViewModel/ThemeOneVM.swift @@ -50,7 +50,7 @@ class ThemeOneVM{ } func initView(){ - requestIDFA() +// requestIDFA() AuthFunc.shareInstance.initTimePeriods() startInitialTimer() // moveCloudView() @@ -76,7 +76,7 @@ class ThemeOneVM{ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let themeOneAd = adsData.result?.filter({$0.forPage == AdsEnum.themeOne.rawValue}).first, let bannerImage = themeOneAd.bannerImage{ + if let themeOneAd = adsData.result?.filter({$0.slug == AdsEnum.themeOne.rawValue}).first, let bannerImage = themeOneAd.advertisement?.bannerImage{ vc.adBanner.imageURL(bannerImage, color: .textDarkBlue) vc.adBanner.isHidden = false } @@ -315,7 +315,7 @@ class ThemeOneVM{ //check url from api if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let themeOneAd = adsData.result?.filter({$0.forPage == AdsEnum.themeOne.rawValue}).first, let adLink = themeOneAd.adLink, let adID = themeOneAd.id{ + if let themeOneAd = adsData.result?.filter({$0.slug == AdsEnum.themeOne.rawValue}).first, let adLink = themeOneAd.advertisement?.adLink, let adID = themeOneAd.id{ PersistentStorage.shared.addAdsCount(adID: adID,clicks: 1) if let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { diff --git a/WOKA/Theme/ViewModel/ThemeTwoVM.swift b/WOKA/Theme/ViewModel/ThemeTwoVM.swift index 0bf9bf6..5b155ad 100644 --- a/WOKA/Theme/ViewModel/ThemeTwoVM.swift +++ b/WOKA/Theme/ViewModel/ThemeTwoVM.swift @@ -53,11 +53,14 @@ class ThemeTwoVM{ self.playLiveTV() } - // configuring the google ads. - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: { [weak self] in - guard let self else{return} - AdReusable.sharedInstance.setupBannerAd(bannerView: bannerView, in: vc.adView, adUnitID: K.GoogleAdIDs.splashBanner1, viewController: self.vc, height: 8, width: 15) - }) + if let adsData = AuthFunc.shareInstance.adsData, let themeTwoAD = adsData.result?.filter({$0.slug == AdsEnum.themeTwo.rawValue}).first, themeTwoAD.googleAd != nil{ + // Show google ads if its configured from backend. + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: { [weak self] in + guard let self else{return} + AdReusable.sharedInstance.setupBannerAd(bannerView: bannerView, in: vc.adView, adUnitID: K.GoogleAdIDs.splashBanner1, viewController: self.vc, height: 8, width: 15) + }) + } + } private func handleNotificationCenter(){ diff --git a/WOKA/WOKAFM/ViewModel/WokaFMVM.swift b/WOKA/WOKAFM/ViewModel/WokaFMVM.swift index d6b0093..6d854d7 100644 --- a/WOKA/WOKAFM/ViewModel/WokaFMVM.swift +++ b/WOKA/WOKAFM/ViewModel/WokaFMVM.swift @@ -154,14 +154,16 @@ class WokaFMVM{ func setGoogleAd(){ - /* - Show google ads with dispatch queue. - */ - DispatchQueue.main.asyncAfter(deadline: .now() + 0.8, execute: { [weak self] in - guard let self else{return} - AdReusable.sharedInstance.setupBannerAd(bannerView: self.bottomBannerView, in: vc.adView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc) -// vc.adView.isHidden = false - }) + if let adsData = AuthFunc.shareInstance.adsData, let fmAd = adsData.result?.filter({$0.slug == AdsEnum.fm.rawValue}).first, fmAd.googleAd != nil{ + /* + Show google ads with dispatch queue. + */ + DispatchQueue.main.asyncAfter(deadline: .now() + 0.8, execute: { [weak self] in + guard let self else{return} + AdReusable.sharedInstance.setupBannerAd(bannerView: self.bottomBannerView, in: vc.adView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc) + }) + } + } // MARK: - Setup AV & Player diff --git a/WOKA/WebSeries/Controller/WebSeriesVC.swift b/WOKA/WebSeries/Controller/WebSeriesVC.swift index 705f56a..29f9cd8 100644 --- a/WOKA/WebSeries/Controller/WebSeriesVC.swift +++ b/WOKA/WebSeries/Controller/WebSeriesVC.swift @@ -97,7 +97,7 @@ class WebSeriesVC: UIViewController { */ if let adsData = AuthFunc.shareInstance.adsData{ // check if ads data contains ad for webseries - if let webSeriesAd = adsData.result?.filter({$0.forPage == AdsEnum.web_series.rawValue}).first, let adID = webSeriesAd.id{ + if let webSeriesAd = adsData.result?.filter({$0.slug == AdsEnum.web_series.rawValue}).first, let adID = webSeriesAd.advertisement?.id{ PersistentStorage.shared.addAdsCount(adID: adID ,impressions: 1) } } @@ -113,9 +113,9 @@ class WebSeriesVC: UIViewController { @IBAction func playTrailer(_ sender: LocalisedElementsButton) { //If its ads then nav user to webview - if let adsData = AuthFunc.shareInstance.adsData, let webSeriesAd = adsData.result?.filter({$0.forPage == AdsEnum.web_series.rawValue}).first{ + if let adsData = AuthFunc.shareInstance.adsData, let webSeriesAd = adsData.result?.filter({$0.slug == AdsEnum.web_series.rawValue}).first{ // check if ads data contains ad for webseries - if let adLink = webSeriesAd.adLink,let adID = webSeriesAd.id{ + if let adLink = webSeriesAd.advertisement?.adLink,let adID = webSeriesAd.advertisement?.id{ PersistentStorage.shared.addAdsCount(adID: adID ,clicks: 1) if let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url) diff --git a/WOKA/WebSeries/ViewModel/WebSeriesVM.swift b/WOKA/WebSeries/ViewModel/WebSeriesVM.swift index e2077d1..9be50e4 100644 --- a/WOKA/WebSeries/ViewModel/WebSeriesVM.swift +++ b/WOKA/WebSeries/ViewModel/WebSeriesVM.swift @@ -70,37 +70,16 @@ class WebSeriesVM{ } checkAds() - - /* - MAke logic for ads - */ -// if let adsData = AuthFunc.shareInstance.adsData{ -// // check if ads data contains ad for webseries -// if let webSeriesAd = adsData.result?.filter({$0.forPage == AdsEnum.web_series.rawValue}).first{ -// vc.headerViewImage.addTapGesture { -// if let adID = webSeriesAd.id{ -// PersistentStorage.shared.addAdsCount(adID: adID ,clicks: 1) -// } -// if let adLink = webSeriesAd.adLink ,let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { -// UIApplication.shared.open(url) -// } -// } -// } -// } } func checkAds(){ - /* - This is test ad. + First check if webSeries ad is present via slug, then check for Local Ads, if not then check google ads. */ - - /* - MAke logic for ads - */ - if let adsData = AuthFunc.shareInstance.adsData, let webSeriesAd = adsData.result?.filter({$0.forPage == AdsEnum.web_series.rawValue}).first{ - // check if ads data contains ad for webseries - if let bannerImage = webSeriesAd.bannerImage, let buttonImage = webSeriesAd.buttonImage{ + if let adsData = AuthFunc.shareInstance.adsData, let webSeriesAd = adsData.result?.filter({$0.slug == AdsEnum.web_series.rawValue}).first{ + + // check if ads data contains LocalAD for webseries + if let advertisement = webSeriesAd.advertisement,let bannerImage = advertisement.bannerImage, let buttonImage = advertisement.buttonImage{ vc.headerViewImage.imageURL(bannerImage, color: .white) vc.headerBtn.setTitle("", for: .normal) vc.headerViewLabel.text = "" @@ -112,55 +91,21 @@ class WebSeriesVM{ if let adID = webSeriesAd.id{ PersistentStorage.shared.addAdsCount(adID: adID ,clicks: 1) } - if let adLink = webSeriesAd.adLink ,let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { + if let adLink = webSeriesAd.advertisement?.adLink ,let url = URL(string: adLink), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url) } } - } - }else{ - DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: { [weak self] in - guard let self else{return} + }else{ + // check google ads + if webSeriesAd.googleAd != nil{ + DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: { [weak self] in + guard let self else{return} - AdReusable.sharedInstance.setupBannerAd(bannerView: self.headerBannerView, in: vc.headerView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc) - AdReusable.sharedInstance.setupBannerAd(bannerView: self.masilaBannerView, in: vc.masilaTrailerView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc, height: 8, width: 15) - }) -// let viewWidth = vc.headerView.frame.inset(by: vc.headerView.safeAreaInsets).width -// -// // Here the current interface orientation is used. Use -// // GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth or -// // GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth if you prefer to load an ad of a -// // particular orientation, -// let adaptiveSize = GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth) -// headerBannerView = GADBannerView(adSize: adaptiveSize) -// headerBannerView.delegate = self.vc -// headerBannerView.center = vc.headerView.center -// -// headerBannerView.frame = CGRect(x: 0, y: 0, width: vc.headerView.frame.width, height: vc.headerView.frame.height) -// vc.headerView.addSubview(headerBannerView) -// headerBannerView.adUnitID = "K.GoogleAdIDs.themeTwo" -// headerBannerView.rootViewController = self.vc -// headerBannerView.load(GADRequest()) -// headerBannerView.layoutIfNeeded() -// -// var bannerView2 = GADBannerView() -// -// let viewWidth2 = vc.masilaTrailerView.frame.inset(by: vc.masilaTrailerView.safeAreaInsets).width -// -// // Here the current interface orientation is used. Use -// // GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth or -// // GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth if you prefer to load an ad of a -// // particular orientation, -// let adaptiveSize2 = GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth2) -// bannerView2 = GADBannerView(adSize: adaptiveSize2) -// -// bannerView2.center = vc.masilaTrailerView.center -// -// bannerView2.frame = CGRect(x: 0, y: 0, width: vc.masilaTrailerView.frame.width, height: vc.masilaTrailerView.frame.height) -// vc.masilaTrailerView.addSubview(bannerView2) -// bannerView2.adUnitID = K.GoogleAdIDs.themeTwo -// bannerView2.rootViewController = self.vc -// bannerView2.load(GADRequest()) -// bannerView2.layoutIfNeeded() + AdReusable.sharedInstance.setupBannerAd(bannerView: self.headerBannerView, in: vc.headerView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc) + AdReusable.sharedInstance.setupBannerAd(bannerView: self.masilaBannerView, in: vc.masilaTrailerView, adUnitID: K.GoogleAdIDs.themeTwo, viewController: self.vc, height: 8, width: 15) + }) + } + } } }