Skip to content

Commit

Permalink
Fix: banner not disappear immediately after IAP purchased
Browse files Browse the repository at this point in the history
  • Loading branch information
ayaysir committed Feb 29, 2024
1 parent 3292d84 commit 4305a33
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions DiffuserStick/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

// // IAP Test only - Must be removed when distributing
// UserDefaults.standard.set(false, forKey: InAppProducts.productIDs[0])

UNUserNotificationCenter.current().delegate = self // <- push 추가
GADMobileAds.sharedInstance().start(completionHandler: nil) // <- AdMob 초기화
return true
Expand Down
10 changes: 10 additions & 0 deletions DiffuserStick/ViewController/ActiveListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ class ActiveListViewController: UIViewController, AddDelegate {
NotificationCenter.default.addObserver(self, selector: #selector(appOpened), name: UIApplication.didBecomeActiveNotification, object: nil)
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

if !AdManager.default.isReallyShowAd && bannerView != nil {
bannerView.removeFromSuperview()
// constraint 원상복구
constraintBottom.constant = +50
}
}

@objc func appClosed() {
print("===== app closed =====")
UserDefaults.standard.setValue(Date(), forKey: "last-closed-date")
Expand Down
6 changes: 6 additions & 0 deletions DiffuserStick/ViewController/ArchiveViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class ArchiveViewController: UIViewController {
print(error)
}
}

if !AdManager.default.isReallyShowAd && bannerView != nil {
bannerView.removeFromSuperview()
// constraint 원상복구
constraintBottom.constant = -50
}
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extension HelpViewController: GADBannerViewDelegate {
bannerView.rootViewController = self
bannerView.load(GADRequest())
bannerView.delegate = self
cnstWebViewBottom.constant += adSize.size.height
cnstWebViewBottom.constant -= adSize.size.height
}

private func addBannerViewToView(_ bannerView: GADBannerView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ extension SettingTableViewController: GADBannerViewDelegate {
bannerView.rootViewController = self
bannerView.load(GADRequest())
bannerView.delegate = self

}

private func addBannerViewToView(_ bannerView: GADBannerView) {
Expand Down Expand Up @@ -301,10 +300,10 @@ extension SettingTableViewController {
LoadingIndicatorUtil.default.hide(self)

// 2. 세팅VC 광고 제거 (나머지 뷰는 다시 들어가면 제거되어 있음)
// removeBannerView()
bannerView.removeFromSuperview()

// 3. 버튼
// changePurchaseButtonStyle(isPurchased: true)
tableView.reloadData()
}
}
}
Expand Down

0 comments on commit 4305a33

Please sign in to comment.