/ZYAdKit

Primary LanguageSwiftMIT LicenseMIT

ZYAdKit

[![CI Status](https://img.shields.io/travis/Yu Yang/ZYAdKit.svg?style=flat)](https://travis-ci.org/Yu Yang/ZYAdKit) Version License Platform

##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