Comments (1)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let entry = applicationEntry()!
self.window = UIWindow(viewController: entry, backgroundColor: .white)
launchAd(entry)
return true
}
import UIKit
import ZLaunchAd
struct AdModel {
var imgUrl: String!
var duration: Int!
var width: CGFloat!
var height: CGFloat!
var animationType: ZLaunchAnimationType!
var skipBtnType: ZLaunchSkipButtonType!
init(_ dic: Dictionary<String, Any>) {
imgUrl = dic["imgUrl"] as! String
duration = dic["duration"] as! Int
width = dic["width"] as! CGFloat
height = dic["height"] as! CGFloat
let btnType = dic["skipBtnType"] as! Int
skipBtnType = ZLaunchSkipButtonType(rawValue: btnType)!
let animationType = dic["animationType"] as! Int
self.animationType = ZLaunchAnimationType(rawValue: animationType)!
}
}
func launchAd(_ homeVC: UIViewController) {
let adView = ZLaunchAd.create()
request { model in
let buttonConfig = ZLaunchSkipButtonConfig()
buttonConfig.skipBtnType = model.skipBtnType
let imageResource = ZLaunchAdImageResourceConfigure()
imageResource.imageNameOrImageURL = model.imgUrl
imageResource.animationType = model.animationType
imageResource.imageDuration = model.duration
imageResource.imageFrame = CGRect(x: 0, y: 0, width: screenWidth, height: screenWidth*model.height/model.width)
/// 设置图片、跳过按钮
adView.setImageResource(imageResource, buttonConfig: buttonConfig, action: {
let vc = UIViewController()
vc.view.backgroundColor = UIColor.yellow
homeVC.navigationController?.pushViewController(vc, animated: true)
})
}
}
//MARK: - 请求数据,此处解析json文件
func request(_ completion: @escaping (AdModel)->()) -> Void {
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
if let path = Bundle.main.path(forResource: "AdData", ofType: "json") {
let url = URL(fileURLWithPath: path)
do {
let data = try Data(contentsOf: url)
let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
if let dict = json as? [String: Any],
let dataArray = dict["data"] as? [[String: Any]] {
/// 随机显示
let idx = Int(arc4random()) % dataArray.count
let model = AdModel(dataArray[idx])
completion(model)
}
} catch {
log.error(error)
}
}
}
}
from zlaunchad.
Related Issues (20)
- Redefinition of module 'CommonCrypto' HOT 8
- carthage xcode10 报错 HOT 1
- 不支持swift4.2
- TabbarController是不是不能用你的框架,似乎只有NavigationController才适用。 HOT 1
- 设置等待时间为1s ,图片加载不出来是什么原因呢 HOT 3
- 首次广告页还是会,一闪而过,不知道怎么定位问题呢
- 加载广告,还是会出现一闪而过,这种问题
- please fix compile wrong by CocoaPods in Xcode 10.2.1 and Swift 5
- 代码更新有问题和master不一致 HOT 1
- 内存暴涨能看下嘛
- 卡在广告页,不得动弹
- 网络不好导致的卡在广告页
- pod下来不是最新的 HOT 2
- 带倒计时的跳过按钮显示不全
- please support Swift Package Manager HOT 1
- 跳过 显示不全 , 如果网络不好时,会卡在开屏页,可否提供主动关闭的方法 HOT 1
- ZLaunchAd 網絡不好的時候 會閃退
- iOS15 有崩溃 能看下吗
- 提几点优化建议:
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zlaunchad.