FBAudienceNetwork与IOS Swift Xcode中的强保留周期集成

时间:2018-03-19 01:52:49

标签: swift facebook

我正在使用FBAudienceNetwork开发Swift IOS应用程序。我可以在我的应用表列表中显示Facebook广告。但是,当我使用Xcode 9.2调试内存图来检查是否存在任何内存泄漏问题时,它会显示FBPlaceholderObject的强保留周期。我的代码段如下:

import FBAudienceNetwork 

class TableViewAdsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, FBNativeAdDelegate, FBNativeAdsManagerDelegate {

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        configureAdManagerAndLoadAds()
    }

    func configureAdManagerAndLoadAds() {

        if adsManager == nil {
            adsManager = FBNativeAdsManager(placementID: "<facebookID_placeID>", forNumAdsRequested: 5)
            weak var weakSelf = self
            adsManager.delegate = weakSelf
            adsManager.loadAds()
        }
    }

    func nativeAdsFailedToLoadWithError(_ error: Error) {
        print("Cant load the ads", error)
    }

    func nativeAdDidClick(_ nativeAd: FBNativeAd) {
        print("Ad tapped: \(String(describing: nativeAd.title))")
    }

    func nativeAdsLoaded() {

        weak var adsMgr = adsManager
        adsCellProvider = FBNativeAdTableViewCellProvider(manager: adsMgr!, for: FBNativeAdViewType.genericHeight120)
        weak var weakSelf = self
        adsCellProvider.delegate = weakSelf

        if tblAdsDemo != nil {
            tblAdsDemo.reloadData()
        }
    }

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if adsCellProvider != nil {
            return Int(adsCellProvider.adjustCount(UInt(self.sampleData.count), forStride: UInt(adRowStep)))
        }
        else {
            return sampleData.count
        }
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        if adsCellProvider != nil && adsCellProvider.isAdCell(at: indexPath as IndexPath, forStride: UInt(adRowStep)) {
            return adsCellProvider.tableView(tableView, cellForRowAt: indexPath as IndexPath)
        }
        else {
            let cell = tableView.dequeueReusableCell(withIdentifier: "idCellSample", for: indexPath as IndexPath) as! SampleCell
            cell.lblTitle.text = sampleData[indexPath.row - Int(indexPath.row / adRowStep)]
            return cell
        }
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

        if adsCellProvider != nil && adsCellProvider.isAdCell(at: indexPath, forStride: UInt(adRowStep)) {
            return adsCellProvider.tableView(tableView, heightForRowAt: indexPath)
        }
        else {
            return 60.0
        }
    }

Xcode的调试内存图的屏幕截图:

enter image description here

如何从中进一步调试?

0 个答案:

没有答案