Giter Site home page Giter Site logo

进不去 about zlaunchad HOT 1 CLOSED

mqzhot avatar mqzhot commented on July 28, 2024
进不去

from zlaunchad.

Comments (1)

wakaryry avatar wakaryry commented on July 28, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.