SmartAd 0.1.9

SmartAd 0.1.9

shock 维护。



 
依赖项
Firebase/Core>= 0
Firebase/AdMob>= 0
FBAudienceNetwork>= 0
 

SmartAd 0.1.9

  • ShockUtility

License Platform GitHub release English Korea Japan

SmartAd

SmartAd 是一个针对 iOS 和 Android 上的 AdMob 和 Audience Network 广告框架的易于使用的库。

安装

SmartAd 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中

pod 'SmartAd'

依赖项

pod 'Firebase/Core'
pod 'Firebase/AdMob'
pod 'FBAudienceNetwork'

开发环境

  • XCode 9.3
  • Swift4
  • FirebaseCore (4.0.19)
  • Google-Mobile-Ads-SDK (7.30.0)
  • FBAudienceNetwork (4.28.1)

支持的广告格式

谷歌AdMob

  • AdView
  • 横幅广告
  • 激励视频广告

脸书受众网络

  • AdView
  • 横幅广告
  • 激励视频广告

使用方式

SmartAdBanner

截图在Storyboard中添加一个视图,将自定义视图更改为'SmartAdBanner',然后 فقط仅设置属性,无需编写代码即可使其工作。
如果需要返回值,请设置代理并按照如下实现SmartAdBannerDelegate。

extension ViewController: SmartAdBannerDelegate {
    func smartAdBannerDone(_ view: SmartAdBanner) {
        // Success...
    }

    func smartAdBannerFail(_ error: Error?) {
        // Fail...
    }
}

* 注意:为了让isAutoHeight值生效,必须将高度值分配给AutoAdBanner的Auto Layout。当每个平台的广告加载时,高度值会根据广告大小进行调整。如果失败,值设置为0,且在屏幕上不显示。
* 注意:如果最小宽度大于300或320(取决于尺寸格式),SmartAdBanner将正常显示。

SmartAdInterstitial

以下调用插页广告的示例代码。

var interstitialAd: SmartAdInterstitial?

override func viewDidLoad() {
	super.viewDidLoad()
    
	interstitialAd = SmartAdInterstitial(self, adOrder: .random,
                                         googleID: "googleID", facebookID: "facebookID")
	interstitialAd?.loadAd()
}

如果您想返回结果,请使用SmartAdInterstitialDelegate。

extension ViewController: SmartAdInterstitialDelegate {
    func smartAdInterstitialDone() {
        // Success...
    }
    
    func smartAdInterstitialFail(_ error: Error?) {
        // Fail...
    }
}

SmartAdInterstitial类的功能

public convenience init(_ controller: UIViewController, adOrder: SmartAdOrder,
                        googleID: String?, facebookID: String?, isShowAfterLoad: Bool = true)
public convenience init(_ controller: UIViewController, adOrder: SmartAdOrder,
                        googleID: String?, facebookID: String?)
public func loadAd(delayMilliseconds: Double = 0.0)
public func showAd() -> Bool

SmartAdAward

以下调用奖励广告的示例代码。

var awardAd: SmartAdAward?

override func viewDidLoad() {
    super.viewDidLoad()

    awardAd = SmartAdAward.init(self, adOrder: .google, googleID: "googleID", facebookID: "facebookID")
    awardAd?.showAd()
}

如果您想返回结果,请使用SmartAdAwardDelegate。

extension ViewController: SmartAdAwardDelegate {
    func smartAdAwardDone(_ isGoogle: Bool, _ isAwardShow: Bool, _ isAwardClick: Bool) {
        // Success...
    }
    
    func smartAdAwardFail(_ error: Error?) {
        // Fail...
    }
}

SmartAdAward类的功能

public convenience init(_ controller: UIViewController, adOrder: SmartAdOrder,
                       googleID: String?, facebookID: String?)
public func showAd()

SmartAdAlertController

Screenshot 仅包含OK按钮的警告。

SmartAdAlertController.alert(self,
                            adOrder: .random,
                            googleID: "googleID",
                            facebookID: "facebookID",
                            title: "Alert") { (_) in
   // Clicked OK
}

包含OK和取消的警告。

SmartAdAlertController.confirm(self,
                               adOrder: .google,
                               googleID: "googleID",
                               facebookID: "facebookID",
                               title: "Confirm") { (isOK) in
   if isOK {
       // Clicked OK
   } else {
       // Clicked Cancel
   }
}

自定义警告。

SmartAdAlertController.select(self,
                              adOrder: .facebook,
                              googleID: "googleID",
                              facebookID: "facebookID",
                              title: "Select",
                              titleOK: "Yes",
                              titleCancel: "No") { (isOK) in
   if isOK {
       // Clicked Yes
   } else {
       // Clicked No
   }
}

添加测试设备

SmartAd.addTestDevice(type: .google, ids: [kGADSimulatorID, "XXXXX"])
SmartAd.addTestDevice(type: .facebook, ids: ["XXXXX","YYYYY"])

注册广告激活函数

您可以使用此函数在应用内付费或某些情况下停止广告。

SmartAd.IsShowAdFunc = { () in
    // You can customize the content to suit your situation.
    // Here's an example that applies to all ad classes except SmartAdAward.
    let def = UserDefaults.standard
    let isShowAd = def.bool(forKey: "isShowAd")
    return ([SmartAdBanner.self, SmartAdInterstitial.self, SmartAdAlertController.self], isShowAd)
}

许可

The MIT License

Copyright (c) 2009-2017 ShockUtility.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.