@IBActionfuncopenDebugOptions(sender:AnyObject){// TODO: Replace YOUR_AD_UNIT_ID with your own ad unit ID.letdebugOptionsViewController=DebugOptionsViewController(adUnitID:"YOUR_AD_UNIT_ID")self.present(debugOptionsViewController,animated:true,completion:nil)}
Objective-C
-(IBAction)openDebugOptions:(id)sender{// TODO: Replace YOUR_AD_UNIT_ID with your own ad unit ID.GADDebugOptionsViewController*debugOptionsViewController=[GADDebugOptionsViewControllerdebugOptionsViewControllerWithAdUnitID:@"YOUR_AD_UNIT_ID"];[selfpresentViewController:debugOptionsViewControlleranimated:YEScompletion:nil];}
[null,null,["最后更新时间 (UTC):2025-08-21。"],[[["\u003cp\u003eThis guide explains how to debug ad serving in your mobile app using in-app preview and the Delivery Inspector.\u003c/p\u003e\n"],["\u003cp\u003eIn-app preview lets you see your own creatives rendered within your app for testing and verification.\u003c/p\u003e\n"],["\u003cp\u003eThe Delivery Inspector provides information on which ads were delivered to help troubleshoot unexpected ad behavior.\u003c/p\u003e\n"],["\u003cp\u003eTo use these tools, you need to prepare your app by integrating necessary code, link your device to your Ad Manager account, and push creatives for previewing.\u003c/p\u003e\n"]]],["This guide details how to use in-app preview and the Delivery Inspector for ad debugging. To begin, add a function to your app to open the SDK's debug options menu. Link your device via the \"Creative Preview\" option within this menu and log into Ad Manager. Subsequently, push a creative to your linked device from Ad Manager and re-select \"Creative Preview\" to verify device linking. Finally load the ad in the ad slot to see your creative. To troubleshoot ad delivery use the Delivery Inspector.\n"],null,["# Creative Preview & Delivery Inspector\n\nThis guide shows how to debug ad serving using in-app preview and the\nDelivery Inspector.\n\n[In-app preview](//support.google.com/admanager/answer/7160685)\nlets you see your own creatives rendered within your mobile app.\nThis preview is especially useful for publishers who have creatives\nthat interact with the app, have unique behavior, or rely on the app\nfor some of their rendering (including native creatives and MRAID).\n\nThe [Delivery\nInspector](//support.google.com/admanager/answer/7449957)\ngives information on which ads were delivered. When unexpected ads deliver,\nuse the Delivery Inspector to find out why.\n\nPrerequisites\n-------------\n\n- Version 7.13.1 or higher of the Google Mobile Ads SDK\n- Access to a Google Ad Manager account\n- Complete [Get Started](/ad-manager/mobile-ads-sdk/ios/quick-start)\n\nPrepare your app\n----------------\n\nDebugging requires interaction with the SDK's debug options menu.\nThe recommended way to open the menu is to include the function\nbelow in your app, and trigger it based on a user action: \n\n### Swift\n\n @IBAction func openDebugOptions(sender: AnyObject) {\n // TODO: Replace YOUR_AD_UNIT_ID with your own ad unit ID.\n let debugOptionsViewController = DebugOptionsViewController(adUnitID: \"YOUR_AD_UNIT_ID\")\n self.present(debugOptionsViewController, animated: true, completion: nil)\n }\n\n### Objective-C\n\n - (IBAction)openDebugOptions:(id)sender {\n // TODO: Replace YOUR_AD_UNIT_ID with your own ad unit ID.\n GADDebugOptionsViewController *debugOptionsViewController =\n [GADDebugOptionsViewController debugOptionsViewControllerWithAdUnitID:@\"YOUR_AD_UNIT_ID\"];\n [self presentViewController:debugOptionsViewController animated:YES completion:nil];\n }\n\nAny valid ad unit from your Ad Manager account is sufficient to open the\ndebug options menu.\n| **Note:** Another way to open the menu is to do a swipe gesture on the creative, but it doesn't work for all ad formats such as native ads, and you must be careful to not click the ad when attempting to swipe. Calling the method above is much more robust.\n\nGet notified when the debug menu closes\n---------------------------------------\n\nWhen opening the debug options menu programmatically, you may choose\nto implement `GADDebugOptionsViewControllerDelegate` to be notified\nwhen the view controller is dismissed. To do this, make your class\nconform to the delegate: \n\n### Swift\n\n```swift\nimport GoogleMobileAds\n \nclass ViewController: UIViewController, GADDebugOptionsViewControllerDelegate {\n}\n```\n\n### Objective-C\n\n```objective-c\n@import GoogleMobileAds;\n \n@interface ViewController : UIViewController \u003cGADDebugOptionsViewControllerDelegate\u003e {\n}\n \n@end\n```\n\nSet the delegate on your `GADDebugOptionsViewController`: \n\n### Swift\n\n```swift\n@IBAction func openDebugOptions(sender: AnyObject) {\n let debugOptionsViewController = GADDebugOptionsViewController(adUnitID: \"YOUR_AD_UNIT_ID\")\n debugOptionsViewController.delegate = self\n self.present(debugOptionsViewController, animated: true, completion: nil)\n}\n```\n\n### Objective-C\n\n```objective-c\n- (IBAction)openDebugOptions:(id)sender {\n GADDebugOptionsViewController *debugOptionsViewController =\n [GADDebugOptionsViewController debugOptionsViewControllerWithAdUnitID:@\"YOUR_AD_UNIT_ID\"];\n debugOptionsViewController.delegate = self;\n [self presentViewController:debugOptionsViewController animated:YES completion:nil];\n}\n```\n\nFinally, implement the delegate: \n\n### Swift\n\n func debugOptionsViewControllerDidDismiss(controller: GADDebugOptionsViewController) {\n print(\"Debug options view controller dismissed.\")\n }\n\n### Objective-C\n\n - (void)debugOptionsViewControllerDidDismiss:(GADDebugOptionsViewController *)controller {\n NSLog(@\"Debug options view controller dismissed.\");\n }\n\nLink your device\n----------------\n\nAfter adding the capability to open the debug options menu, run your\napp and trigger the function above. The following menu opens:\n\nSelect **Creative Preview** to link your device. A browser opens\nand automatically navigates you to a browser to log in to Ad Manager. After\nsuccessfully logging in, name your device to register it with your\nAd Manager account, and click **Verify**.\n\n| **Note:** `SFSafariViewController` is opened on iOS 9 and above, while `Safari` is opened on iOS 8 and below.\n\nYou have successfully linked your device! At this point, you can\nsee your device linked in the [Ad Manager front-end](//www.google.com/dfp).\nYou can also [allow others to access your\ndevices](//support.google.com/admanager/answer/7160685#access).\n\nIn-app preview\n--------------\n\nFollow the steps to\n[push a creative to your linked device](//support.google.com/admanager/answer/7160685#push).\nMake sure that the pushed creative is part of an active line item\ntargeted to the ad slot where you want to see the creative.\n\nAfter pushing a creative from the front-end, trigger the debug\noptions menu on your device again, and select **Creative Preview**\nagain. This step lets the SDK check Ad Manager again to verify that the\ndevice linking was successful and to get some information about\nwhich creative you pushed. If device linking was previously successful,\nthe debug menu closes immediately. If it was unsuccessful,\nyou're prompted to link your account again.\n\nFinally, load an ad for the slot you wish to preview to see your creative!\n\nDelivery Inspector\n------------------\n\nFollow the [Begin app troubleshooting](//support.google.com/admanager/answer/7180401)\nsteps to troubleshoot your app. If you complete the steps successfully, the\nrequest will show up in the Ad Manager frontend and you can view more info about the ad\nthat served."]]