ZYAdKit 1.2

ZYAdKit 1.2

yangyu 维护。



 
依赖项
Kingfisher>= 0
Google-Mobile-Ads-SDK~> 7.69.0
 

  • Yu Yang

ZYAdKit

[![CI 状态](https://img.shields.io/travis/Yu Yang/ZYAdKit.svg?style=flat)](https://travis-ci.org/Yu Yang/ZYAdKit) 版本 许可 平台

##1. 从后台读取配置

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
	[ServiceApi getConfig];
}

UserDefaults.standard.setValue(json, forKey: "kAdInfo")
UserDefaults.standard.synchronize()

AdManager.shared.cacheDatas()

##2. 设置 config

图1

    1. 先设置 config,将要显示的 rootViewController 传过去
    1. 加载假的 launchView,和真的 launchView 一模一样的 view,如上图
    1. 获取占位的 VC 显示
    1. 未获取到,则加载自己的 rootViewController
let config = AdConfig()
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainVc = storyboard.instantiateInitialViewController()!
config.rootViewController = mainVc
AdManager.shared.setConfig(config)


let placeholderLaunchView = Bundle.main.loadNibNamed("PlaceholderLaunchView", owner: nil, options: nil)?.first as! UIView
        
if let placeholderLaunchVc = AdManager.shared.getPlaceholderViewController(with: placeholderLaunchView) {
	window = UIWindow(frame: UIScreen.main.bounds)
	window?.rootViewController = placeholderLaunchVc
} else {
	window = UIWindow(frame: UIScreen.main.bounds)
	window?.rootViewController = mainVc
}
window?.makeKeyAndVisible()

##3. 在 info.plist 里设置 admob key

<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>

注意项 ##1. Main Interface 要清空,从代码加载 图1