Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Constants
- {
- static let adColonyAppID = "app0da80fed71f14b81b0"
- static let adColonyZoneID = "vzc8cf608f563b470c8f"
- static let userID = "Dy9X6wfmfoO94GtSYw2fysp4I0YGB6ji"
- }
- class AdColonyPartner: Partner {
- var fetchedAd: AdColonyInterstitial?
- init() {
- }
- func initAdColony(from controller: UIViewController?) -> AdColonyPartner{
- let opt: AdColonyAppOptions = AdColonyAppOptions()
- opt.userID = Constants.userID
- AdColony.configure(withAppID: Constants.adColonyAppID, zoneIDs: [Constants.adColonyZoneID], options: nil) { (zones) in
- self.requestInterstitial(from: controller)
- }
- return self
- }
- func requestInterstitial(from controller: UIViewController?) {
- NSLog("requesting Video...");
- if let cntr = controller {
- //AlertManager.shared.showProgressDialog(from: cntr)
- }
- AdColony.requestInterstitial(inZone: Constants.adColonyZoneID, options: nil, success: { (videoAd) in
- NSLog("Video loaded ");
- videoAd.setOpen({
- NSLog("Ad opened");
- })
- videoAd.setClose({
- NSLog("Ad closed");
- self.fetchedAd = nil
- })
- videoAd.setExpire({
- NSLog("Ad expired");
- self.fetchedAd = nil
- })
- videoAd.setClick({
- NSLog("Ad clicked");
- })
- self.fetchedAd = videoAd
- if let cntr = controller {
- // hiding progress
- // AlertManager.shared.hideProgress()
- self.fetchedAd!.show(withPresenting: cntr)
- }
- }) { (adError) in
- NSLog("SAMPLE_APP: Request failed with error: " + adError.localizedDescription + " and suggestion: " + adError.localizedRecoverySuggestion!)
- AlertManager.shared.hideProgress()
- }
- }
- override func showAd(from controller: UIViewController) {
- if let ad = fetchedAd {
- if (!ad.expired) {
- ad.show(withPresenting: controller)
- }
- }else {
- requestInterstitial(from: controller)
- }
- }
- override func getName() -> String {
- return "AdColony"
- }
- override func getAlertMessage() -> String {
- return "AdColony"
- }
- }
- // MainViewController for testing ad
- private func setUpNavigationBar(){
- let backButton = UIBarButtonItem(title: "", style: .plain, target: navigationController, action: nil)
- self.navigationItem.backBarButtonItem = backButton
- self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(adTapped))
- adcolony = AdColonyPartner().initAdColony()
- }
- @objc fileprivate func adTapped() {
- // body method here
- adcolony!. showAd(from: self)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement