Upgrade to Pro — share decks privately, control downloads, hide ads and more …

アドフリくんSDKをSwift4で組み込む

 アドフリくんSDKをSwift4で組み込む

Beba158ac4c0f2aa7fa2ee15b2ae4ff3?s=128

studioshin

June 25, 2018
Tweet

Transcript

  1. ΞυϑϦ͘ΜSDKΛSwift4Ͱ૊ΈࠐΉ ΠϯλʔεςΠγϟϧ ωΠςΟϒ ಈըΠϯλʔεςΠγϟϧ ಈըωΠςΟϒ ಈըϦϫʔυ όφʔ *OΞυϑϦδϡΫ

  2. ΞυϑϦ͘Μ4%,ͷಋೖ IUUQTBEGVSJLVOKQBEGVSJLVO ·ͣ͸ΞΧ΢ϯτొ࿥

  3. ΠϯλʔεςΠγϟϧ ωΠςΟϒ όφʔ

  4. ΞυϑϦ͘Μ4%,ͷಋೖ μ΢ϯϩʔυϖʔδ͔Β4%,Λμ΢ϯϩʔυ ޿ࠂ࿮Λ࡞ͬͯɺ޿ࠂ*%Λൃߦ͢Δɻ

  5. ΞυϑϦ͘Μ4%,ͷಋೖ ϓϩδΣΫτʹ4%,Λ௥Ճ 4%,Λυϥοάˍυϩοϓɻ

  6. ΞυϑϦ͘Μ4%,ͷಋೖ ϑϨʔϜϫʔΫΛ௥Ճ

  7. ΞυϑϦ͘Μ4%,ͷಋೖ ϒϦοδϔομͷ௥Ճ 0CKFDUJWF$ͷద౰ͳΫϥ εΛ௥Ճɻ͋ͱͰফ͢ɻ

  8. ΞυϑϦ͘Μ4%,ͷಋೖ ϒϦοδϔομͷ௥Ճ ίϯύΠϧઃఆʹϒϦοδ ϔομ͕௥Ճ͞ΕΔɻ

  9. όφʔʗΠϯλʔεςΠγϟϧ

  10. όφʔʗΠϯλʔεςΠγϟϧ޿ࠂͷදࣔ ϒϦοδϔομ΁هೖ #import <adfurikunsdk/AdfurikunView.h> #import <adfurikunsdk/AdfurikunPopupView.h>

  11. func makeBannerAd() { let adfurikunView = AdfurikunView(frame: CGRect(x: 0, y:

    0, width: 320, height: 50)) self.view.addSubview(adfurikunView) adfurikunView.appID = “޿ࠂID” adfurikunView.transitionDulation = 0.5 adfurikunView.testModeEnable() // ςετϞʔυ adfurikunView.startShowAd() adfurikunView.center = CGPoint(x: self.view.frame.size.width/2, y: self.view.frame.size.height - 25) } όφʔ޿ࠂͷදࣔ 6*7JFX$POUSPMMFSʹදࣔ͢Δ૝ఆ
  12. όφʔ޿ࠂͷදࣔ

  13. ΠϯλʔεςΠγϟϧ޿ࠂͷදࣔ 6*7JFX$POUSPMMFSʹදࣔ͢Δ૝ఆ var adfurikunInter: AdfurikunPopupView! func makeInterstisialAd() { self.adfurikunInter =

    AdfurikunPopupView() self.adfurikunInter.appID = “޿ࠂID” self.adfurikunInter.testModeEnable() // ςετϞʔυ self.adfurikunInter.setSchedule(1) self.adfurikunInter.preloadAd() } @IBAction func showInterstisialAd(_ sender: Any) { self.view.addSubview(self.adfurikunInter) self.adfurikunInter.center = CGPoint(x: self.view.frame.size.width/2, y: self.view.frame.size.height/2) self.adfurikunInter.preloadShowAd() }
  14. ΠϯλʔεςΠγϟϧ޿ࠂͷදࣔ 6*7JFX$POUSPMMFSʹදࣔ͢Δ૝ఆ

  15. ωΠςΟϰ

  16. ωΠςΟϒ޿ࠂͷදࣔ ϒϦοδϔομ΁هೖ #import <adfurikunsdk/AdfurikunNativeAd.h> #import <adfurikunsdk/AdfurikunNativeAdInfo.h>

  17. ωΠςΟϒ޿ࠂͷදࣔ var adfurikunNative: AdfurikunNativeAd! var nativeLinkURL: URL? //޿ࠂϦϯΫ var imageView:

    UIImageView! //޿ࠂը૾ var titleLabel: UILabel! //޿ࠂλΠτϧ var textLabel: UILabel! //޿ࠂςΩετ var nativeAdView: UIView! //޿ࠂදࣔϏϡʔ ޿ࠂදࣔ༻ͷϓϩύςΟΛఆٛ
  18. ωΠςΟϒ޿ࠂͷදࣔ func nativeAd(size: CGSize) -> UIView { let adView =

    UIView(frame: CGRect(x: 0, y: 0, width: size.width, height: size.height)) self.nativeAdView = adView adView.backgroundColor = UIColor.white //ը૾ self.imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: size.height, height: size.height)) imageView.contentMode = .scaleAspectFit adView.addSubview(imageView) //λΠτϧ self.titleLabel = UILabel(frame: CGRect(x: size.height + 5.0, y: 0, width: size.width - (size.height + 5.0), height: size.height * 0.3)) titleLabel.numberOfLines = 2 titleLabel.minimumScaleFactor = 0.5 adView.addSubview(titleLabel) //ςΩετ self.textLabel = UILabel(frame: CGRect(x: size.height + 5.0, y: size.height * 0.3, width: size.width - (size.height + 5.0), height: size.height * 0.7)) textLabel.numberOfLines = 4 textLabel.minimumScaleFactor = 0.5 adView.addSubview(textLabel) ޿ࠂදࣔ༻ͷϏϡʔΛ࡞Δ
  19. ωΠςΟϒ޿ࠂͷදࣔ self.adfurikunNative = AdfurikunNativeAd(“޿ࠂID”) self.adfurikunNative.delegate = self self.adfurikunNative.getNativeAd() return adView

    } ޿ࠂදࣔ༻ͷϏϡʔΛ࡞Δ σϦήʔτΛઃఆ AdfurikunNativeAdDelegate
  20. ωΠςΟϒ޿ࠂͷදࣔ func apiDidFinishLoading(_ nativeAdInfo: AdfurikunNativeAdInfo, adnetworkKey networkKey: String!) { if

    let url = URL(string: nativeAdInfo.img_url) { let task = URLSession.shared.dataTask(with: url) { data, response, error in if let d = data, error == nil{ DispatchQueue.main.async { self.imageView.image = UIImage(data: d) //ը૾ self.titleLabel.text = nativeAdInfo.title //λΠτϧ self.textLabel.text = nativeAdInfo.text //ςΩετ //ϦϯΫ if let url = nativeAdInfo.link_url { self.nativeLinkURL = URL(string: url) } //λοϓδΣενϟʔ let tapGesture = UITapGestureRecognizer(target: self.nativeAdView, action: #selector(self.naitiveAdTap(_:))) self.nativeAdView.addGestureRecognizer(tapGesture) } } } task.resume() } } func apiDidFailWithError(_ err: Int32, adnetworkKey: String!) { print("Native Ad error: \(adnetworkKey)=\(err)") } σϦήʔτϝιουͰϦιʔεΛऔಘ ϝΠϯεϨουͰઃఆ AdfurikunNativeAdDelegate λοϓΛݕ஌Ͱ͖ΔΑ͏ʹ ͢Δɻ
  21. ωΠςΟϒ޿ࠂͷදࣔ @objc func naitiveAdTap(_ tap: UITapGestureRecognizer) { if let url

    = self.nativeLinkURL, UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHandler: { (ok) in AdfurikunNativeAdInfo.makeInstance().recClick() }) } } ޿ࠂΫϦοΫͷ௨஌
  22. ωΠςΟϒ޿ࠂͷදࣔ

  23. ಈըΠϯλʔεςΠγϟϧ ಈըωΠςΟϒ ಈըϦϫʔυ

  24. ΞυϑϦ͘Μಈը4%,ͷಋೖ μ΢ϯϩʔυϖʔδ͔Β4%,Λμ΢ϯϩʔυ ֤ΞυωοτϫʔΫͷઃఆ͸ɺ ͜ͷϚχϡΞϧΛ͝ཡ͍ͩ͘͞ɻ ʢ͜͜Ͱ͸ׂѪ͠·͢ʣ $PDPB1PETΛ࢖͏ํ๏ָ͕ʂ

  25. ΞυϑϦ͘Μಈը4%,ͷಋೖ ϓϩδΣΫτʹ4%,Λ௥Ճ 4%,Λυϥοάˍυϩοϓɻ BEOFUXPSLT

  26. ΞυϑϦ͘Μ4%,ͷಋೖ ϑϨʔϜϫʔΫΛ௥Ճ

  27. ϒϦοδϔομ΁هೖ JNQPSU"%'.PWJF3FXBSE"%'NZ.PWJF3FXBSEI JNQPSU"%'.PWJF3FXBSE"%'NZ.PWJF*OUFSTUJUJBMI JNQPSU"%'.PWJF3FXBSE"%'NZ.PWJF/BUJWFI JNQPSU"%'.PWJF3FXBSE"%'NZ.PWJF/BUJWF"E7JFXI JNQPSU"%'.PWJF3FXBSE"%'NZ.PWJF/BUJWF"E'MFYI JNQPSU"%'.PWJF3FXBSE"%'.PWJF0QUJPOTI ΞυϑϦ͘Μಈը4%,ͷಋೖ

  28. ಈըωΠςΟϰ

  29. ಈըωΠςΟϒ޿ࠂͷදࣔ var adfurikunMovieNativeView: ADFmyMovieNativeAdView! var videoNativeAdView: UIView! //ಈըωΠςΟϰ޿ࠂදࣔϏϡʔ ޿ࠂදࣔ༻ͷϓϩύςΟΛఆٛ

  30. ಈըωΠςΟϒ޿ࠂͷදࣔ if ADFmyMovieNativeAdView.isSupportedOSVersion() { ADFmyMovieNativeAdView.configure(withAppID: “޿ࠂID”) } ॳظԽ ىಈ௚ޙʹ࣮ߦ

  31. ಈըωΠςΟϒ޿ࠂͷදࣔ func makeVideoNativeView(size: CGSize) -> UIView { let rect =

    CGRect(x: 0, y: 0, width: size.width, height: size.height) let adView: UIView = UIView(frame: rect) if ADFmyMovieNativeAdView.isSupportedOSVersion() { self.adfurikunMovieNativeView = ADFmyMovieNativeAdView(appID: “޿ࠂID”, layoutPattern: .default) self.adfurikunMovieNativeView.autoLoad = true self.adfurikunMovieNativeView.loadAndNotify(to: self) } self.videoNativeAdView = adView return adView } ޿ࠂදࣔ༻ͷϏϡʔΛ࡞Δ σϦήʔτΛઃఆ ADFmyMovieNativeAdViewDelegate
  32. ಈըωΠςΟϒ޿ࠂͷදࣔ //޿ࠂͷऔಘ੒ޭ func onNativeMovieAdViewLoadFinish(_ appID: String) { if let adv

    = self.adfurikunMovieNativeView.getAdView() { adv.bounds = CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height) self.addSubview(adv) adv.center = CGPoint(x: self.frame.size.width / 2, y: self.frame.size.height / 2) self.adfurikunMovieNativeView.setVideoDelegate(self) self.adfurikunMovieNativeView.playVideo() } } //޿ࠂͷऔಘࣦഊ func onNativeMovieAdViewLoadError(_ error: ADFMovieError, appID: String) { print("ωΠςΟϰ޿ࠂͷऔಘࣦഊ:\(error.errorMessage)") } ಈըͷऔಘ σϦήʔτΛઃఆ ADFmyNativeAdViewVideoDelegate ADFmyMovieNativeAdViewDelegate
  33. ಈըωΠςΟϒ޿ࠂͷදࣔ ಈըͷ࠶ੜ֬ೝσϦήʔτ //޿ࠂͷ࠶ੜ։࢝ func onNativeMovieAdViewPlayStart(_ appID: String) { print("޿ࠂͷ࠶ੜ։࢝:\(appID)") }

    //޿ࠂͷ࠶ੜ׬ྃ func onNativeMovieAdViewPlayFinish(_ appID: String, isVideo: Bool) { print("޿ࠂͷ࠶ੜ׬ྃ:\(appID) isVideo=\(isVideo)") } //޿ࠂͷ࠶ੜࣦഊ func onNativeMovieAdViewPlayFail(_ appID: String, error: ADFMovieError) { print("޿ࠂͷ࠶ੜࣦഊ:\(appID) \(error.errorMessage)") } ADFmyNativeAdViewVideoDelegate
  34. ಈըΠϯλʔεςΠγϟϧ

  35. ಈըΠϯλʔεςΠγϟϧ޿ࠂͷදࣔ if ADFmyMovieInterstitial.isSupportedOSVersion() { ADFmyMovieInterstitial.initWithAppID(“޿ࠂID”, viewController: self) } if let

    ad = ADFmyMovieInterstitial.getInstance(“޿ࠂID”, delegate: self) { if ad.isPrepared() { ad.play(withPresenting: self) } } ॳظԽ දࣔ ىಈ௚ޙʹ࣮ߦ σϦήʔτΛઃఆ ADFmyMovieRewardDelegate
  36. // ޿ࠂͷදࣔ४උ͕ऴΘͬͨ func adsFetchCompleted(_ isTestMode_inApp: Bool) { } // ޿ࠂͷද͕ࣔ։͔࢝ͨ͠

    func adsDidShow(_ adnetworkKey: String) { } // ޿ࠂͷදࣔΛ࠷ޙ·ͰऴΘ͔ͬͨ func adsDidCompleteShow() { } // ಈը޿ࠂ࠶ੜΤϥʔ࣌ͷΠϕϯτ func adsPlayFailed() { } // ޿ࠂΛดͨ࣌͡ͷΠϕϯτ func adsDidHide() { } ಈըΠϯλʔεςΠγϟϧ޿ࠂͷදࣔ σϦήʔτϝιου ADFmyMovieRewardDelegate σϦήʔτͷϓϩτίϧ͸ɺ ಈըϦϫʔυͱಉ͡ʂ ಈըϦϫʔυͷ৔߹ɺ͜ͷσϦήʔτϝιο υ͕ݺ͹Εͨ࣌఺ͰɺใुΛ༩͑Δɻ
  37. ಈըϦϫʔυ

  38. ಈըϦϫʔυ޿ࠂͷදࣔ ޿ࠂදࣔ༻ͷϓϩύςΟΛఆٛ var adfurikunMovieReward: ADFmyMovieReward!

  39. ॳظԽ දࣔ ಈըϦϫʔυ޿ࠂͷදࣔ if ADFmyMovieReward.isSupportedOSVersion() { ADFmyMovieReward.initWithAppID(“޿ࠂID”, viewController: self) self.adfurikunMovieReward

    = ADFmyMovieReward.getInstance(“޿ࠂID”, delegate: self) } ىಈ௚ޙʹ࣮ߦ if self.adfurikunMovieReward.isPrepared() == true { self.adfurikunMovieReward.play() } else { print("ADF ޿ࠂͷऔಘ͕׬͍ྃͯ͠·ͤΜ") } σϦήʔτΛઃఆ ADFmyMovieRewardDelegate
  40. // ޿ࠂͷදࣔ४උ͕ऴΘͬͨ func adsFetchCompleted(_ isTestMode_inApp: Bool) { } // ޿ࠂͷද͕ࣔ։͔࢝ͨ͠

    func adsDidShow(_ adnetworkKey: String) { } // ޿ࠂͷදࣔΛ࠷ޙ·ͰऴΘ͔ͬͨ func adsDidCompleteShow() { } // ಈը޿ࠂ࠶ੜΤϥʔ࣌ͷΠϕϯτ func adsPlayFailed() { } // ޿ࠂΛดͨ࣌͡ͷΠϕϯτ func adsDidHide() { } ಈըϦϫʔυ޿ࠂͷදࣔ σϦήʔτϝιου ADFmyMovieRewardDelegate ͜ͷσϦήʔτϝιου͕ݺ͹Εͨ࣌఺Ͱɺ ใुΛ༩͑Δɻ
  41. ΞυϑϦ͘ΜSDKΛSwift4Ͱ૊ΈࠐΉ *OΞυϑϦδϡΫ Ҏ্ɺ Ͳ͏΋͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ