{"_id":"59a3dbfabbd9f300238bef9c","project":"574ff4bd3fa1870e00889ba6","version":{"_id":"574ff4bd3fa1870e00889ba9","project":"574ff4bd3fa1870e00889ba6","__v":26,"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","5a0322bf044b6f001c236e36","5a79897c5b6e430030746df6","5a79898c2b2d5f0012cbab63","5ab3b5e3d2d1e2006252a8f2","5b1a43bd678eab0003aa54a4","5b6d95e29d346300038baff3"],"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","githubsync":"","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-08-28T09:01:46.991Z","link_external":false,"link_url":"","sync_unique":"","hidden":true,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"PubNative's Native Ads follow the natural form and function of the user experience. Native Ads take the shape into which they are placed. They provide content of the ad to the publisher, it's up to the publisher to make a design of the ad according to the app.\n[block:api-header]\n{\n  \"title\": \"Getting Started\"\n}\n[/block]\n* Before integrating Native Ads into your app, you’ll need to create an account on PubNative and integrate the PubNative iOS SDK into your project.\n* Add a Native Ad unit to your app in the PubNative dashboard.\n* Make sure you have added the ad network SDKs you wish to use to your app.\n\nFor Native Ads, first, you need to create a request then fill it with your data and start it providing a callback for the ad response.\n[block:api-header]\n{\n  \"title\": \"Integration Steps\"\n}\n[/block]\n* [Request Native Ad](http://developers.pubnative.net/docs/native-ads#request-native-ad)\n* [Fill View With Data](http://developers.pubnative.net/docs/native-ads#fill-view-with-data)\n* [Track Native Ad](http://developers.pubnative.net/docs/native-ads#track-native-ad)\n[block:api-header]\n{\n  \"title\": \"Request Native Ad\"\n}\n[/block]\nIn order to request an ad, you need to create a request, fill it with your data and start it providing a callback for the ad response.\n\nYou can set up several data before starting the request by using the **PNRequest** helper methods. This is an optional usage but in the long term, it will seriously improve your ad placement behavior.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let request = PNRequest()\\nrequest.start(withAppToken:\\\"<APP_TOKEN>\\\", placementName:\\\"<PLACEMENT_NAME>\\\", delegate: self)\",\n      \"language\": \"swift\",\n      \"name\": \"Swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PNRequest *request = [[PNRequest alloc] init];\\n[request startWithAppToken::::at:::\\\"<APP_TOKEN>\\\" placementName:@\\\"<PLACEMENT_NAME>\\\" delegate: self];\",\n      \"language\": \"objectivec\",\n      \"name\": \"Objective-C\"\n    }\n  ]\n}\n[/block]\nFor getting callbacks from **PNRequest**, you should implement **PNRequestDelegate** for your class:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"class YourClass: PNRequestDelegate\\n{\\n//...\\nfunc pubnativeRequestDidStart(_ request: PNRequest!) \\n{\\n    // Request started\\n}\\n    \\nfunc pubnativeRequest(_ request: PNRequest!, didFail error: Error!) \\n{\\n    // Request failed\\n}\\n    \\nfunc pubnativeRequest(_ request: PNRequest!, didLoad ad: PNAdModel!) \\n{\\n    // Request return the Ad\\n}\\n//...\\n}\",\n      \"language\": \"swift\",\n      \"name\": \"Swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@interface YourClass () <PNRequestDelegate>\\n//...\\n-(void)pubnativeRequestDidStart:(PNRequest *)request\\n{\\n    // Request started\\n}\\n\\n-(void)pubnativeRequest:(PNRequest *)request didLoad:(PNAdModel *)ad\\n{\\n    // Request return the Ad\\n}\\n\\n-(void)pubnativeRequest:(PNRequest *)request didFail:(NSError *)error\\n{\\n    // Request failed\\n}\\n//...\",\n      \"language\": \"objectivec\",\n      \"name\": \"Objective-C\"\n    }\n  ]\n}\n[/block]\n**Cache Resource**\nBy default, resources would be cached before serving the ad. You can set it to false as follows in order to use URLs to download resources like an icon, banner etc.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"request.cacheResources = Bool\",\n      \"language\": \"swift\",\n      \"name\": \"Swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"request.cacheResources = BOOL;\",\n      \"language\": \"objectivec\",\n      \"name\": \"Objective-C\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Fill View With Data\"\n}\n[/block]\nTo display Native Ads, you need to create a renderer instance, (type of **PNAdModelRenderer**) and bind all your view elements into it and then pass this instance to **PNAdModel**'s `renderAd()` method:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let renderer = PNAdModelRenderer()\\nrenderer.titleView = adTitle               // Ad's title view\\nrenderer.descriptionView = adDescription   // Ad's description view\\nrenderer.iconView = adIcon                 // Ad's icon view\\nrenderer.bannerView = adBanner             // Ad's banner view\\nrenderer.starRatingView = adRating         // Ad's rating view\\nrenderer.callToActionView = adCallToAction // Ad's CTA view\\nrenderer.contentInfoView = contentInfo     // Ad's content info view\\n\\nadModel.(renderer)\",\n      \"language\": \"swift\",\n      \"name\": \"Swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PNAdModelRenderer *renderer = [[PNAdModelRenderer alloc] init];\\nrenderer.titleView = adTitle;               // Ad's title view\\nrenderer.descriptionView = adDescription;   // Ad's description view\\nrenderer.iconView = adIcon;                 // Ad's icon view\\nrenderer.bannerView = adBanner;             // Ad's banner view\\nrenderer.starRatingView = adRating;         // Ad's rating view\\nrenderer.callToActionView = adCallToAction; // Ad's CTA view\\nrenderer.contentInfoView = contentInfo;     // Ad's content info view\\n\\n[adModel renderAd:renderer];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nThe adModel will automatically fill bounded views with right data.\n[block:api-header]\n{\n  \"title\": \"Track Native Ad\"\n}\n[/block]\nOnce you have rendered your ad, you should make the model start tracking your view so we can confirm the impression and handle the clicks, this can be done with the following method from the **PNAdModel**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"adModel.startTrackingView(<AD_CONTAINER_VIEW>, with: <YOUR_CONTROLLER>)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[adModel startTrackingView:<AD_CONTAINER_VIEW> withViewController:<YOUR_CONTROLLER>];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nIf your ad is removed from the screen or you're exiting the ViewController, you'll need to stop the tracking process with the following method:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"adModel.stopTracking()\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[adModel stopTracking];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nYou can also set up a **PNAdModelDelegate** to listen for callbacks on the tracking process.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"class YourClass: PNAdModelDelegate \\n{\\n//...\\nadModel.delegate = self\\n//...\\nfunc pubantiveAdDidConfirmImpression(ad: PNAdModel!)\\n{\\n    //Impression was just recorded\\n}\\n\\nfunc pubnativeAdDidClick(ad: PNAdModel!)\\n{\\n    //The ad was clicked, the ad will be opened right after this\\n}\\n//...\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@interface YourInterface () PNAdModelDelegate\\n//...\\nadModel.delegate = self;\\n//...\\n- (void)pubantiveAdDidConfirmImpression:(PNAdModel *)ad\\n{\\n    //Impression was just recorded\\n}\\n\\n- (void)pubnativeAdDidClick:(PNAdModel *)ad\\n{\\n    //The ad was clicked, the ad will be opened right after this\\n}\\n//...\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"native-ads","type":"basic","title":"Native Ads"}
PubNative's Native Ads follow the natural form and function of the user experience. Native Ads take the shape into which they are placed. They provide content of the ad to the publisher, it's up to the publisher to make a design of the ad according to the app. [block:api-header] { "title": "Getting Started" } [/block] * Before integrating Native Ads into your app, you’ll need to create an account on PubNative and integrate the PubNative iOS SDK into your project. * Add a Native Ad unit to your app in the PubNative dashboard. * Make sure you have added the ad network SDKs you wish to use to your app. For Native Ads, first, you need to create a request then fill it with your data and start it providing a callback for the ad response. [block:api-header] { "title": "Integration Steps" } [/block] * [Request Native Ad](http://developers.pubnative.net/docs/native-ads#request-native-ad) * [Fill View With Data](http://developers.pubnative.net/docs/native-ads#fill-view-with-data) * [Track Native Ad](http://developers.pubnative.net/docs/native-ads#track-native-ad) [block:api-header] { "title": "Request Native Ad" } [/block] In order to request an ad, you need to create a request, fill it with your data and start it providing a callback for the ad response. You can set up several data before starting the request by using the **PNRequest** helper methods. This is an optional usage but in the long term, it will seriously improve your ad placement behavior. [block:code] { "codes": [ { "code": "let request = PNRequest()\nrequest.start(withAppToken:\"<APP_TOKEN>\", placementName:\"<PLACEMENT_NAME>\", delegate: self)", "language": "swift", "name": "Swift" } ] } [/block] [block:code] { "codes": [ { "code": "PNRequest *request = [[PNRequest alloc] init];\n[request startWithAppToken:@\"<APP_TOKEN>\" placementName:@\"<PLACEMENT_NAME>\" delegate: self];", "language": "objectivec", "name": "Objective-C" } ] } [/block] For getting callbacks from **PNRequest**, you should implement **PNRequestDelegate** for your class: [block:code] { "codes": [ { "code": "class YourClass: PNRequestDelegate\n{\n//...\nfunc pubnativeRequestDidStart(_ request: PNRequest!) \n{\n // Request started\n}\n \nfunc pubnativeRequest(_ request: PNRequest!, didFail error: Error!) \n{\n // Request failed\n}\n \nfunc pubnativeRequest(_ request: PNRequest!, didLoad ad: PNAdModel!) \n{\n // Request return the Ad\n}\n//...\n}", "language": "swift", "name": "Swift" } ] } [/block] [block:code] { "codes": [ { "code": "@interface YourClass () <PNRequestDelegate>\n//...\n-(void)pubnativeRequestDidStart:(PNRequest *)request\n{\n // Request started\n}\n\n-(void)pubnativeRequest:(PNRequest *)request didLoad:(PNAdModel *)ad\n{\n // Request return the Ad\n}\n\n-(void)pubnativeRequest:(PNRequest *)request didFail:(NSError *)error\n{\n // Request failed\n}\n//...", "language": "objectivec", "name": "Objective-C" } ] } [/block] **Cache Resource** By default, resources would be cached before serving the ad. You can set it to false as follows in order to use URLs to download resources like an icon, banner etc. [block:code] { "codes": [ { "code": "request.cacheResources = Bool", "language": "swift", "name": "Swift" } ] } [/block] [block:code] { "codes": [ { "code": "request.cacheResources = BOOL;", "language": "objectivec", "name": "Objective-C" } ] } [/block] [block:api-header] { "title": "Fill View With Data" } [/block] To display Native Ads, you need to create a renderer instance, (type of **PNAdModelRenderer**) and bind all your view elements into it and then pass this instance to **PNAdModel**'s `renderAd()` method: [block:code] { "codes": [ { "code": "let renderer = PNAdModelRenderer()\nrenderer.titleView = adTitle // Ad's title view\nrenderer.descriptionView = adDescription // Ad's description view\nrenderer.iconView = adIcon // Ad's icon view\nrenderer.bannerView = adBanner // Ad's banner view\nrenderer.starRatingView = adRating // Ad's rating view\nrenderer.callToActionView = adCallToAction // Ad's CTA view\nrenderer.contentInfoView = contentInfo // Ad's content info view\n\nadModel.(renderer)", "language": "swift", "name": "Swift" } ] } [/block] [block:code] { "codes": [ { "code": "PNAdModelRenderer *renderer = [[PNAdModelRenderer alloc] init];\nrenderer.titleView = adTitle; // Ad's title view\nrenderer.descriptionView = adDescription; // Ad's description view\nrenderer.iconView = adIcon; // Ad's icon view\nrenderer.bannerView = adBanner; // Ad's banner view\nrenderer.starRatingView = adRating; // Ad's rating view\nrenderer.callToActionView = adCallToAction; // Ad's CTA view\nrenderer.contentInfoView = contentInfo; // Ad's content info view\n\n[adModel renderAd:renderer];", "language": "objectivec" } ] } [/block] The adModel will automatically fill bounded views with right data. [block:api-header] { "title": "Track Native Ad" } [/block] Once you have rendered your ad, you should make the model start tracking your view so we can confirm the impression and handle the clicks, this can be done with the following method from the **PNAdModel** [block:code] { "codes": [ { "code": "adModel.startTrackingView(<AD_CONTAINER_VIEW>, with: <YOUR_CONTROLLER>)", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "[adModel startTrackingView:<AD_CONTAINER_VIEW> withViewController:<YOUR_CONTROLLER>];", "language": "objectivec" } ] } [/block] If your ad is removed from the screen or you're exiting the ViewController, you'll need to stop the tracking process with the following method: [block:code] { "codes": [ { "code": "adModel.stopTracking()", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "[adModel stopTracking];", "language": "objectivec" } ] } [/block] You can also set up a **PNAdModelDelegate** to listen for callbacks on the tracking process. [block:code] { "codes": [ { "code": "class YourClass: PNAdModelDelegate \n{\n//...\nadModel.delegate = self\n//...\nfunc pubantiveAdDidConfirmImpression(ad: PNAdModel!)\n{\n //Impression was just recorded\n}\n\nfunc pubnativeAdDidClick(ad: PNAdModel!)\n{\n //The ad was clicked, the ad will be opened right after this\n}\n//...\n}", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "@interface YourInterface () PNAdModelDelegate\n//...\nadModel.delegate = self;\n//...\n- (void)pubantiveAdDidConfirmImpression:(PNAdModel *)ad\n{\n //Impression was just recorded\n}\n\n- (void)pubnativeAdDidClick:(PNAdModel *)ad\n{\n //The ad was clicked, the ad will be opened right after this\n}\n//...", "language": "objectivec" } ] } [/block]