{"_id":"59a3dbfabbd9f300238bef9c","project":"574ff4bd3fa1870e00889ba6","version":{"_id":"574ff4bd3fa1870e00889ba9","project":"574ff4bd3fa1870e00889ba6","__v":21,"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"],"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:01:46.991Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"[block:api-header]\n{\n  \"title\": \"Getting Started\"\n}\n[/block]\nPubnative's native advertisements follow the natural form and function of the user experience. Native advertisements take the shape into which they are placed. Native ads provide contents of the ad to the publisher, it's up to the publisher to make a design of the ad according to the app.\n\n* Before integrating native ads in your app, you’ll need to create an account on the PubNative Dashboard, and integrate the 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, after sending, provide your ad with a callback for the ad response.\n[block:api-header]\n{\n  \"title\": \"Requesting Native Ads\"\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 helper **PNRequest** methods. This is an optional usage but in the long term will seriously improve your ad placement behavior.\n\nHere is a sample on how to use it.\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//...\\nfunc pubnativeRequestDidStart(_ request: PNRequest!) {\\n    // Request started\\n}\\n    \\nfunc pubnativeRequest(_ request: PNRequest!, didFail error: Error!) {\\n    // Request failed\\n}\\n    \\nfunc pubnativeRequest(_ request: PNRequest!, didLoad ad: PNAdModel!) {\\n    // Request return the Ad\\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-(void)pubnativeRequest:(PNRequest *)request didLoad:(PNAdModel*)ad\\n{\\n    // Request return the Ad\\n}\\n-(void)pubnativeRequest:(PNRequest *)request didFail:(NSError*)error\\n{\\n    // Request failed\\n}\",\n      \"language\": \"objectivec\",\n      \"name\": \"Objective-C\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Cache Resource\"\n}\n[/block]\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\"\n}\n[/block]\nTo display native ad on screen, you need to create new class **PNAdModelRenderer** and bind all your views into it and then pass this class into **pubnativeAdModel.renderAd()**:\n\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\\npubnativeAdModel.renderAd(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[pubnativeAdModel renderAd:renderer];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nPubnative AdModel will automatically fill binded views with right data.\n[block:api-header]\n{\n  \"title\": \"Track Native Ad\"\n}\n[/block]\nOnce you have your ad rendered, 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\": \"pubnativeAdModel.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\": \"[pubnativeAdModel 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 activity, you'll need to stop the tracking process with the following method:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"pubnativeAdModel.stopTracking()\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[pubnativeAdModel 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//...\\npubnativeAdModel.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      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@interface YourInterface () PNAdModelDelegate\\n//...\\npubnativeAdModel.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\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"native-ads","type":"basic","title":"Native Ads"}
[block:api-header] { "title": "Getting Started" } [/block] Pubnative's native advertisements follow the natural form and function of the user experience. Native advertisements take the shape into which they are placed. Native ads provide contents of the ad to the publisher, it's up to the publisher to make a design of the ad according to the app. * Before integrating native ads in your app, you’ll need to create an account on the PubNative Dashboard, and integrate the 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, after sending, provide your ad with a callback for the ad response. [block:api-header] { "title": "Requesting Native Ads" } [/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 helper **PNRequest** methods. This is an optional usage but in the long term will seriously improve your ad placement behavior. Here is a sample on how to use it. [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//...\nfunc pubnativeRequestDidStart(_ request: PNRequest!) {\n // Request started\n}\n \nfunc pubnativeRequest(_ request: PNRequest!, didFail error: Error!) {\n // Request failed\n}\n \nfunc pubnativeRequest(_ request: PNRequest!, didLoad ad: PNAdModel!) {\n // Request return the Ad\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-(void)pubnativeRequest:(PNRequest *)request didLoad:(PNAdModel*)ad\n{\n // Request return the Ad\n}\n-(void)pubnativeRequest:(PNRequest *)request didFail:(NSError*)error\n{\n // Request failed\n}", "language": "objectivec", "name": "Objective-C" } ] } [/block] [block:api-header] { "title": "Cache Resource" } [/block] 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" } [/block] To display native ad on screen, you need to create new class **PNAdModelRenderer** and bind all your views into it and then pass this class into **pubnativeAdModel.renderAd()**: [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\npubnativeAdModel.renderAd(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[pubnativeAdModel renderAd:renderer];", "language": "objectivec" } ] } [/block] Pubnative AdModel will automatically fill binded views with right data. [block:api-header] { "title": "Track Native Ad" } [/block] Once you have your ad rendered, 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": "pubnativeAdModel.startTrackingView(<AD_CONTAINER_VIEW>, with: <YOUR_CONTROLLER>)", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "[pubnativeAdModel startTrackingView:<AD_CONTAINER_VIEW> withViewController:<YOUR_CONTROLLER>];", "language": "objectivec" } ] } [/block] If your ad is removed from the screen or you're exiting the activity, you'll need to stop the tracking process with the following method: [block:code] { "codes": [ { "code": "pubnativeAdModel.stopTracking()", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "[pubnativeAdModel 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//...\npubnativeAdModel.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}", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "@interface YourInterface () PNAdModelDelegate\n//...\npubnativeAdModel.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}", "language": "objectivec" } ] } [/block]