Skip to content

Commit

Permalink
Feat: added IAP
Browse files Browse the repository at this point in the history
Fix: supplemented localizations
  • Loading branch information
ayaysir committed Mar 6, 2024
1 parent 09e34ef commit db1e70b
Show file tree
Hide file tree
Showing 15 changed files with 575 additions and 91 deletions.
12 changes: 12 additions & 0 deletions MusicScale.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
44DE2C3E2AACBE9F000464E9 /* MIDIListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44DE2C3D2AACBE9F000464E9 /* MIDIListener.swift */; };
44E0ACF1285F0BC6008BBB82 /* NSLayoutConstraint+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44E0ACF0285F0BC6008BBB82 /* NSLayoutConstraint+.swift */; };
44E0ACF3285F3FCD008BBB82 /* UIDevice+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44E0ACF2285F3FCC008BBB82 /* UIDevice+.swift */; };
44E6FDB62B9817F300FF6972 /* IAPHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44E6FDB52B9817F300FF6972 /* IAPHelper.swift */; };
44E7A07528467692005C7909 /* SearchCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44E7A07428467692005C7909 /* SearchCategory.swift */; };
44EE68152853A80B00A6D810 /* Quiz_IntroVC와 InProgressVC에서 무한루프.md in Resources */ = {isa = PBXBuildFile; fileRef = 44EE68142853A80B00A6D810 /* Quiz_IntroVC와 InProgressVC에서 무한루프.md */; };
44EFA4B328541F0800565F93 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 44EFA4B228541F0800565F93 /* GoogleService-Info.plist */; };
Expand Down Expand Up @@ -354,6 +355,7 @@
44DE2C3D2AACBE9F000464E9 /* MIDIListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MIDIListener.swift; sourceTree = "<group>"; };
44E0ACF0285F0BC6008BBB82 /* NSLayoutConstraint+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSLayoutConstraint+.swift"; sourceTree = "<group>"; };
44E0ACF2285F3FCC008BBB82 /* UIDevice+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDevice+.swift"; sourceTree = "<group>"; };
44E6FDB52B9817F300FF6972 /* IAPHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IAPHelper.swift; sourceTree = "<group>"; };
44E7A07428467692005C7909 /* SearchCategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchCategory.swift; sourceTree = "<group>"; };
44EE68142853A80B00A6D810 /* Quiz_IntroVC와 InProgressVC에서 무한루프.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "Quiz_IntroVC와 InProgressVC에서 무한루프.md"; sourceTree = "<group>"; };
44EFA4B228541F0800565F93 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -702,6 +704,7 @@
44709D54276A334F00BBF6C9 /* MusicScale */ = {
isa = PBXGroup;
children = (
44E6FDB42B9817E700FF6972 /* IAP */,
44872B0728608CD900C20E06 /* AdMob */,
4455D1E4285CB40100FB344E /* Audio */,
4426A0082854250800942655 /* Firebase */,
Expand Down Expand Up @@ -842,6 +845,14 @@
path = Main;
sourceTree = "<group>";
};
44E6FDB42B9817E700FF6972 /* IAP */ = {
isa = PBXGroup;
children = (
44E6FDB52B9817F300FF6972 /* IAPHelper.swift */,
);
path = IAP;
sourceTree = "<group>";
};
44EE68132853A7DB00A6D810 /* Report */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1216,6 +1227,7 @@
4417252D284B8FC60003CDC7 /* QuizQuestion.swift in Sources */,
449AF427282EC008008273CA /* ScaleInfoViewController.swift in Sources */,
445FA4C5284E60D70008D621 /* FlashcardsViewController.swift in Sources */,
44E6FDB62B9817F300FF6972 /* IAPHelper.swift in Sources */,
445FA4CC284F547D0008D621 /* InitViewControllerFromStoryboard.swift in Sources */,
445FA4B9284BAE540008D621 /* Array+.swift in Sources */,
4455D1D2285A448200FB344E /* MIDISoundGenerator.swift in Sources */,
Expand Down
91 changes: 49 additions & 42 deletions MusicScale/AdMob/AdsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,55 @@
import Foundation
import GoogleMobileAds

enum AdsError: Error {
case showAdNotAllowed
}

class AdsManager: NSObject {
private override init() {}
static var shared = AdsManager()

/// 배포 시 반드시 true로
static var PRODUCT_MODE: Bool = true

/// 광고 제거 구입했나요?
static var isPurchasedRemoveAd: Bool {
UserDefaults.standard.bool(forKey: InAppProducts.productIDs.first!)
}

/// 최종 광고 표시 여부
static var SHOW_AD: Bool {
return PRODUCT_MODE && !isPurchasedRemoveAd
}
}

extension AdsManager: GADBannerViewDelegate {
private var showAd: Bool {
AdsManager.SHOW_AD
}

func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
// print(#function, bannerView.rootViewController)
}

func bannerViewWillPresentScreen(_ bannerView: GADBannerView) {

}

func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error) {
// print(#function, error.localizedDescription)

NotificationCenter.default.post(name: .networkIsOffline, object: nil)

switch bannerView.rootViewController {
case is ScaleListTableViewController:
break
default:
break
}
}
}

/*
하단 광고 넣는 방법
== Delegate 사용하지 않는 경우 ==
Expand Down Expand Up @@ -59,7 +108,6 @@ import GoogleMobileAds
- MatchKeysViewController (뒤로가기)
*/

@discardableResult
func setupBannerAds(_ viewController: UIViewController, container: UIView? = nil) -> GADBannerView? {

Expand Down Expand Up @@ -95,10 +143,6 @@ func setupBannerAds(_ viewController: UIViewController, container: UIView? = nil
return bannerView
}

enum AdsError: Error {
case showAdNotAllowed
}

/**
전체 화면 광고: 사용 방법
1. 사용할 뷰컨트롤러의 멤버 변수로 `private var interstitial: GADInterstitialAd?` 추가
Expand All @@ -113,40 +157,3 @@ func setupFullAds(_ viewController: UIViewController) async throws -> GADInterst
let request = GADRequest()
return try await GADInterstitialAd.load(withAdUnitID: "ca-app-pub-6364767349592629/6979389977", request: request)
}

class AdsManager: NSObject, GADBannerViewDelegate {

static var shared = AdsManager()

/// 배포 시 반드시 true로
static var PRODUCT_MODE: Bool = false
static var SHOW_AD: Bool {
// ... //
return PRODUCT_MODE && true
}

private var showAd: Bool {
AdsManager.SHOW_AD
}

func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
// print(#function, bannerView.rootViewController)
}

func bannerViewWillPresentScreen(_ bannerView: GADBannerView) {

}

func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error) {
// print(#function, error.localizedDescription)

NotificationCenter.default.post(name: .networkIsOffline, object: nil)

switch bannerView.rootViewController {
case is ScaleListTableViewController:
break
default:
break
}
}
}
Loading

0 comments on commit db1e70b

Please sign in to comment.