在iOS上使用AdMob出现连接错误“权限被拒绝”

时间:2019-01-25 19:32:56

标签: ios swift xcode admob

尝试加载插页式AdMob广告时出现以下连接错误:

[NetworkInfo] Signal strength query returned error: Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied", descriptor: <CTServiceDescriptor 0x281e14840, domain=1, instance=1>

这里的想法是每次加载视图控制器时显示一个广告。该实现基于Google的tutorial。 对于我的applicationID,我已经尝试过自己的测试和google的测试。

我的AppDelegate.swift是:

import UIKit
import GoogleMobileAds

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    // Initialize the Google Mobile Ads SDK.
    GADMobileAds.configure(withApplicationID: "ca-app-pub-3940256099942544~1458002511")  \\ google's test ID

    return true
}

我的viecontroller的扩展名是:

extension MenuViewController: GADInterstitialDelegate {
func createAndLoadInterstitial() -> GADInterstitial {
    let interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")  \\ google's test ID
    interstitial.delegate = self
    interstitial.load(GADRequest())
    return interstitial
}

func interstitialDidDismissScreen(_ ad: GADInterstitial) {
    interstitial = createAndLoadInterstitial()
}

func showAd() {
    if interstitial.isReady {
        interstitial.present(fromRootViewController: self)
    } else {
        print("Ad wasn't ready")
    }
}
}

我在viewdidload中打来的电话:

override func viewDidLoad() {
    super.viewDidLoad()

    // Ads
    interstitial = createAndLoadInterstitial()
    showAd()
...

我的完整日志是:

2019-01-25 19:46:06.192791+0100 TimerApp[9118:2416519] [DYMTLInitPlatform] platform initialization successful
2019-01-25 19:46:06.488342+0100 TimerApp[9118:2416370] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2019-01-25 19:46:06.489723+0100 TimerApp[9118:2416370] [MC] Reading from public effective user settings.
Ad wasn't ready
2019-01-25 19:46:07.492398+0100 TimerApp[9118:2416505] [NetworkInfo] Signal strength query returned error: Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied", descriptor: <CTServiceDescriptor 0x282ac4ce0, domain=1, instance=1>
2019-01-25 19:46:07.745157+0100 TimerApp[9118:2416370] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Speaker (type: Speaker)
2019-01-25 19:46:07.755242+0100 TimerApp[9118:2416505] <Google> To get test ads on this device, call: request.testDevices = @[ @"7df8e261fcfdb632b0663a3e42407e21" ];
2019-01-25 19:46:07.939245+0100 TimerApp[9118:2416540] WF: === Starting WebFilter logging for process TimerApp
2019-01-25 19:46:07.939302+0100 TimerApp[9118:2416540] WF: _userSettingsForUser mobile: {
filterBlacklist =     (
);
filterWhitelist =     (
);
noOverridingAllowed = 1;
restrictWeb = 1;
useContentFilter = 0;
useContentFilterOverrides = 0;
whitelistEnabled = 0;
}
2019-01-25 19:46:07.939346+0100 TimerApp[9118:2416540] WF: _WebFilterIsActive returning: NO
2019-01-25 19:46:10.210927+0100 TimerApp[9118:2416370] Warning: Attempt to present <TimerApp.SettingsViewController: 0x104841450>  on <TimerApp.MenuViewController: 0x105023400> which is already presenting <TimerApp.SettingsViewController: 0x10483cb40>
2019-01-25 19:46:11.557808+0100 TimerApp[9118:2416370] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Speaker (type: Speaker)

1 个答案:

答案 0 :(得分:0)

我知道为什么我的广告没有展示。我尚未及时调用showAd(),而广告尚未加载。日志消息真的使我离开这里。我通过Ajay Saini的链接禁用了它们。