{"_id":"59a3dc0c07e129001944cc27","project":"574ff4bd3fa1870e00889ba6","version":{"_id":"574ff4bd3fa1870e00889ba9","project":"574ff4bd3fa1870e00889ba6","__v":20,"createdAt":"2016-06-02T08:56:29.492Z","releaseDate":"2016-06-02T08:56:29.492Z","categories":["574ff4bd3fa1870e00889baa","577278ecdceb570e003a9001","577279865617b117009e643f","577279985617b117009e6440","577279bc8c48e00e00503504","5774fe18605b770e0037be8a","577ce3ad87acf617003c4187","577f8476a77c700e006a6c52","57b486ae0d2b640e00e9d3f5","57b722133d3e620e004ec74b","57bd95f00fe3a00e003e2cc5","57c8349359cd4b0e00b888ef","57c8349b5754fa1700b12242","57cedb0bad483e0e00890239","57cedbe807d7ea0e00e438cc","57d82967156ef72b007ffcd8","58ee353ad1ee2f0f0034a13d","596623221738df00298622a5","59a51730192dba000fc9ca38","59a8129f1e7b26000fa0fb1a"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"3.0.0","version":"3.0"},"category":{"_id":"57b722133d3e620e004ec74b","__v":0,"version":"574ff4bd3fa1870e00889ba9","project":"574ff4bd3fa1870e00889ba6","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-08-19T15:13:23.417Z","from_sync":false,"order":9,"slug":"ios-native-ads-mediation-layer","title":"iOS SDK"},"user":"5770fa1ce5a0000e0023c680","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-08-28T09:02:04.444Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"The medium layout ad is a mediation of standard units that can be configured from the PubNative dashboard. The medium layout ad view contains a predefined set of components such as, icon, banner, title, description, CTA and disclosure view. You can choose the specific ad type from the PubNative dashboard (i.e. banner only, description-banner-icon or title-icon-description etc.).\n\nThe predefined size for the medium layout ad view is 300 x 250.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/54ed09b-medium.png\",\n        \"medium.png\",\n        153,\n        327,\n        \"#760c7d\"\n      ],\n      \"caption\": \"Medium Layout Example\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Getting Started\"\n}\n[/block]\n  * Before integrating medium layout ads in your app, you’ll need to go through the steps in our Getting started guide, create an account on PubNative and integrate the SDK into your project.\n  * Add a medium layout ad unit to your app in the PubNative dashboard.\n  * Make sure you have added the ad network SDKs you wish to use in your app. \n[block:api-header]\n{\n  \"title\": \"Integration\"\n}\n[/block]\n##1. Create Layout\nYou can create predefined medium layout ad request using **PNMediumLayout** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let mediumLayout = PNMediumLayout()\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PNMediumLayout *mediumLayout = [[PNMediumLayout alloc] init];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n##2. Integrate Lifecycle Callbacks\nYou can track the load process, user interaction and ad behavior with callbacks using **PNLayoutLoadDelegate**.\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"class YourClass: PNLayoutLoadDelegate {\\n//...\\nfunc layoutDidFinishLoading(_ layout: PNLayout!)\\n{\\n    // Layout loaded\\n}\\nfunc layout(_ layout: PNLayout!, didFailLoading error: Error!)\\n{\\n    // Layout load failed\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \":::at:::interface YourClass () <PNLayoutLoadDelegate>\\n//...\\n- (void)layoutDidFinishLoading:(PNLayout *)layout\\n{\\n    // Layout loaded\\n}\\n- (void)layout:(PNLayout *)layout didFailLoading:(NSError *)error\\n{\\n    // Layout load failed\\n}\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nYou can track the tracking process, user interaction and ad behavior with callbacks using PNLayoutTrackDelegate. But you should set delegate only when Layout already loaded. You need to set listener as\n\n\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"class YourClass: PNLayoutTrackDelegate {\\n//...\\nmediumLayout.trackDelegate = self\\n//...\\nfunc layoutTrackClick(_ layout: PNLayout!) {\\n    // Layout click tracked\\n}\\n    \\nfunc layoutTrackImpression(_ layout: PNLayout!) {\\n    // Layout impression tracked\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@interface YourClass () <PNLayoutTrackDelegate>\\n//...\\nmediumLayout.trackDelegate = self;\\n//...\\n- (void)layoutTrackImpression:(PNLayout *)layout\\n{\\n    // Layout impression tracked\\n}\\n- (void)layoutTrackClick:(PNLayout *)layout\\n{\\n    // Layout click tracked\\n}\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n##3. Load Ad\nTo load Medium layout Ad\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"mediumLayout.load(withAppToken: \\\"<YOUR_APP_TOKEN>\\\", placement: \\\"<YOUR_PLACEMENT>\\\", delegate: self)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[mediumLayout loadWithAppToken:@\\\"<YOUR_APP_TOKEN>\\\" placement:@\\\"<YOUR_PLACEMENT>\\\" delegate:self];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nFor getting callbacks from **PNLayout**, you should implement **PNLayoutLoadDelegate** for your class. Once an ad is loaded, You will get a fully created view that can be placed in any View.\n\n##4. Use the ad\nOnce the load callback is over, this layout returns, as a result, an initialized view that can be used inside your own ad container. Impressions and clicks are tracked directly from the SDK, but you need to call **startTrackingView** method so the layout starts listening for clicks and checking the ad on the screen. You can extract the view from **mediumLayout.viewController.view**.\n\nAny interaction with this method without a previously loaded layout will do nothing.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let layoutView = mediumLayout.viewController.view\\n// Inject the view into your view container\\nmediumLayout.startTrackingView()\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"UIView *layoutView = mediumLayout.viewController.view;\\n// Inject the view into your view container\\n[mediumLayout startTrackingView];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nIt is highly recommended that if you have a scrolling view and you want to stop tracking the ad view (which is recommended when the ad disappears from the screen), you can use the **stopTrackingView** method\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"mediumLayout.stopTrackingView()\",\n      \"language\": \"swift\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[mediumLayout stopTrackingView]\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"medium-ad-layouts-1","type":"basic","title":"Medium Ad Layout"}
The medium layout ad is a mediation of standard units that can be configured from the PubNative dashboard. The medium layout ad view contains a predefined set of components such as, icon, banner, title, description, CTA and disclosure view. You can choose the specific ad type from the PubNative dashboard (i.e. banner only, description-banner-icon or title-icon-description etc.). The predefined size for the medium layout ad view is 300 x 250. [block:image] { "images": [ { "image": [ "https://files.readme.io/54ed09b-medium.png", "medium.png", 153, 327, "#760c7d" ], "caption": "Medium Layout Example" } ] } [/block] [block:api-header] { "title": "Getting Started" } [/block] * Before integrating medium layout ads in your app, you’ll need to go through the steps in our Getting started guide, create an account on PubNative and integrate the SDK into your project. * Add a medium layout ad unit to your app in the PubNative dashboard. * Make sure you have added the ad network SDKs you wish to use in your app. [block:api-header] { "title": "Integration" } [/block] ##1. Create Layout You can create predefined medium layout ad request using **PNMediumLayout** [block:code] { "codes": [ { "code": "let mediumLayout = PNMediumLayout()", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "PNMediumLayout *mediumLayout = [[PNMediumLayout alloc] init];", "language": "objectivec" } ] } [/block] ##2. Integrate Lifecycle Callbacks You can track the load process, user interaction and ad behavior with callbacks using **PNLayoutLoadDelegate**. [block:code] { "codes": [ { "code": "class YourClass: PNLayoutLoadDelegate {\n//...\nfunc layoutDidFinishLoading(_ layout: PNLayout!)\n{\n // Layout loaded\n}\nfunc layout(_ layout: PNLayout!, didFailLoading error: Error!)\n{\n // Layout load failed\n}", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "@interface YourClass () <PNLayoutLoadDelegate>\n//...\n- (void)layoutDidFinishLoading:(PNLayout *)layout\n{\n // Layout loaded\n}\n- (void)layout:(PNLayout *)layout didFailLoading:(NSError *)error\n{\n // Layout load failed\n}", "language": "objectivec" } ] } [/block] You can track the tracking process, user interaction and ad behavior with callbacks using PNLayoutTrackDelegate. But you should set delegate only when Layout already loaded. You need to set listener as [block:code] { "codes": [ { "code": "class YourClass: PNLayoutTrackDelegate {\n//...\nmediumLayout.trackDelegate = self\n//...\nfunc layoutTrackClick(_ layout: PNLayout!) {\n // Layout click tracked\n}\n \nfunc layoutTrackImpression(_ layout: PNLayout!) {\n // Layout impression tracked\n}", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "@interface YourClass () <PNLayoutTrackDelegate>\n//...\nmediumLayout.trackDelegate = self;\n//...\n- (void)layoutTrackImpression:(PNLayout *)layout\n{\n // Layout impression tracked\n}\n- (void)layoutTrackClick:(PNLayout *)layout\n{\n // Layout click tracked\n}", "language": "objectivec" } ] } [/block] ##3. Load Ad To load Medium layout Ad [block:code] { "codes": [ { "code": "mediumLayout.load(withAppToken: \"<YOUR_APP_TOKEN>\", placement: \"<YOUR_PLACEMENT>\", delegate: self)", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "[mediumLayout loadWithAppToken:@\"<YOUR_APP_TOKEN>\" placement:@\"<YOUR_PLACEMENT>\" delegate:self];", "language": "objectivec" } ] } [/block] For getting callbacks from **PNLayout**, you should implement **PNLayoutLoadDelegate** for your class. Once an ad is loaded, You will get a fully created view that can be placed in any View. ##4. Use the ad Once the load callback is over, this layout returns, as a result, an initialized view that can be used inside your own ad container. Impressions and clicks are tracked directly from the SDK, but you need to call **startTrackingView** method so the layout starts listening for clicks and checking the ad on the screen. You can extract the view from **mediumLayout.viewController.view**. Any interaction with this method without a previously loaded layout will do nothing. [block:code] { "codes": [ { "code": "let layoutView = mediumLayout.viewController.view\n// Inject the view into your view container\nmediumLayout.startTrackingView()", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "UIView *layoutView = mediumLayout.viewController.view;\n// Inject the view into your view container\n[mediumLayout startTrackingView];", "language": "objectivec" } ] } [/block] It is highly recommended that if you have a scrolling view and you want to stop tracking the ad view (which is recommended when the ad disappears from the screen), you can use the **stopTrackingView** method [block:code] { "codes": [ { "code": "mediumLayout.stopTrackingView()", "language": "swift", "name": null } ] } [/block] [block:code] { "codes": [ { "code": "[mediumLayout stopTrackingView]", "language": "objectivec" } ] } [/block]