{"_id":"59a3eb17bbd9f300238bf0a4","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-28T10:06:15.357Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":13,"body":"PubNative Library is used to implement API based native ads in iOS. PubNative SDK is a mediation layer for integrating multiple ad networks inside your app with the remote control using the PubNative Dashboard.\n\nIt means using PubNative Mediation SDK you can integrate PubNative network as well as other multiple ad networks in your app to implement native and standard ads. If you are using PubNative Library in your app, you can migrate to PubNative SDK by following these simple steps.\n[block:api-header]\n{\n  \"title\": \"Step 1. Requirements\"\n}\n[/block]\nBefore migrating from PubNative Library to PubNative SDK, you need to get **Placement Name** and **App Token** configured in the PubNative Dashboard and OS should be greater than 8.0. Other requirements will remain same for PubNative SDK.\n[block:api-header]\n{\n  \"title\": \"Step 2. Replace Dependency\"\n}\n[/block]\nIf you have imported **PubnativeLibrary.Framework**, remove it from your project and clone the repository and drag'n'drop the **sdk/sdk** folder into your app (be sure to check the \"Copy items into destination group's folder\" option).\n[block:api-header]\n{\n  \"title\": \"Step 3. Change Ad request\"\n}\n[/block]\nPubnative Library uses **PNAdRequestParameters** and **PNAdRequest** for ad request while PubNative SDK uses **PNRequest**. You need to replace ad request from **PNAdRequestParameters** and **PNAdRequest** to **PNRequest** as following :\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#import <PubNativeLibrary/Pubnative.h>\\nPNAdRequestParameters *parameters = [PNAdRequestParameters requestParameters];\\nparameters.app_token = :::at:::\\\"YOUR_APP_TOKEN_HERE\\\";\\n__weak typeof(self) weakSelf = self;\\nself.request = [PNAdRequest request:<YOUR_SELECTED_REQUEST_TYPE>\\n                    withParameters:parameters\\n                     andCompletion:^(NSArray *ads, NSError *error) {\\n   if(error) {\\n       NSLog(@\\\"Pubnative - error requesting ads: %@\\\", [error description]);\\n   }else{\\n       NSLog(@\\\"Pubnative - loaded PNNativeAdModel ads: %d\\\", [ads count]);\\n   }\\n}];\\n[self.request startRequest];\",\n      \"language\": \"text\",\n      \"name\": \"Code\"\n    }\n  ]\n}\n[/block]\nreplace it with\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"let request = PNRequest()\\nrequest.startWithAppToken(\\\"<APP_TOKEN>\\\", placementName: \\\"<PLACEMENT_NAME>\\\", delegate: self)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PNRequest *request = [[PNRequest alloc] init]\\n[request startWithAppToken:\\\"<APP_TOKEN>\\\" placementName:\\\"<PLACEMENT_NAME>\\\" delegate: self]\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Step 4. Track Ad\"\n}\n[/block]\nOnce the ad rendered on screen, 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 PubnativeAdModel. you just need to specify the view that contains the ad along with each item to the startTracking method.\n\nReplace\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#import <PubNativeLibrary/Pubnative.h>\\n[PNTrackingManager trackImpressionWithAd:self.ad\\n                              completion:^(id result, NSError *error)\\n{\\n}];\",\n      \"language\": \"text\",\n      \"name\": \"Code\"\n    }\n  ]\n}\n[/block]\nwith\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"ad.startTrackingView(<AD_CONTAINER_VIEW_GROUP>, withViewController:<CONTROLLER>)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[ad startTrackingView:<AD_CONTAINER_VIEW_GROUP> withViewController:<CONTROLLER>];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nYou can also set up a listener on the model to listen for callbacks on the tracking process.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"class YourClass: PNAdModelDelegate {\\n//...\\nmodel.delegate = self\\n//...\\nfunc pubantiveAdDidConfirmImpression(ad: PNAdModel!)\\n{\\n    //Impression was just recorded\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@interface YourInterface () PNAdModelDelegate\\n//...\\nmodel.delegate = self;\\n//...\\n- (void)pubantiveAdDidConfirmImpression:(PubnativeAdModel *)ad\\n{\\n    //Impression was just recorded\\n}\\n\\n- (void)pubnativeAdDidClick:(PubnativeAdModel *)ad\\n{\\n    //The ad was clicked, the ad will be opened right after this\\n}\",\n      \"language\": \"objectivec\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\nYou can find more about tracking ad view **[here](http://developers.pubnative.net/docs/native-ads#track-native-ad)**.","excerpt":"","slug":"migration-to-sdk-from-library","type":"basic","title":"Migration to SDK from Library"}

Migration to SDK from Library


PubNative Library is used to implement API based native ads in iOS. PubNative SDK is a mediation layer for integrating multiple ad networks inside your app with the remote control using the PubNative Dashboard. It means using PubNative Mediation SDK you can integrate PubNative network as well as other multiple ad networks in your app to implement native and standard ads. If you are using PubNative Library in your app, you can migrate to PubNative SDK by following these simple steps. [block:api-header] { "title": "Step 1. Requirements" } [/block] Before migrating from PubNative Library to PubNative SDK, you need to get **Placement Name** and **App Token** configured in the PubNative Dashboard and OS should be greater than 8.0. Other requirements will remain same for PubNative SDK. [block:api-header] { "title": "Step 2. Replace Dependency" } [/block] If you have imported **PubnativeLibrary.Framework**, remove it from your project and clone the repository and drag'n'drop the **sdk/sdk** folder into your app (be sure to check the "Copy items into destination group's folder" option). [block:api-header] { "title": "Step 3. Change Ad request" } [/block] Pubnative Library uses **PNAdRequestParameters** and **PNAdRequest** for ad request while PubNative SDK uses **PNRequest**. You need to replace ad request from **PNAdRequestParameters** and **PNAdRequest** to **PNRequest** as following : [block:code] { "codes": [ { "code": "#import <PubNativeLibrary/Pubnative.h>\nPNAdRequestParameters *parameters = [PNAdRequestParameters requestParameters];\nparameters.app_token = @\"YOUR_APP_TOKEN_HERE\";\n__weak typeof(self) weakSelf = self;\nself.request = [PNAdRequest request:<YOUR_SELECTED_REQUEST_TYPE>\n withParameters:parameters\n andCompletion:^(NSArray *ads, NSError *error) {\n if(error) {\n NSLog(@\"Pubnative - error requesting ads: %@\", [error description]);\n }else{\n NSLog(@\"Pubnative - loaded PNNativeAdModel ads: %d\", [ads count]);\n }\n}];\n[self.request startRequest];", "language": "text", "name": "Code" } ] } [/block] replace it with [block:code] { "codes": [ { "code": "let request = PNRequest()\nrequest.startWithAppToken(\"<APP_TOKEN>\", placementName: \"<PLACEMENT_NAME>\", delegate: self)", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "PNRequest *request = [[PNRequest alloc] init]\n[request startWithAppToken:\"<APP_TOKEN>\" placementName:\"<PLACEMENT_NAME>\" delegate: self]", "language": "objectivec" } ] } [/block] [block:api-header] { "title": "Step 4. Track Ad" } [/block] Once the ad rendered on screen, 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 PubnativeAdModel. you just need to specify the view that contains the ad along with each item to the startTracking method. Replace [block:code] { "codes": [ { "code": "#import <PubNativeLibrary/Pubnative.h>\n[PNTrackingManager trackImpressionWithAd:self.ad\n completion:^(id result, NSError *error)\n{\n}];", "language": "text", "name": "Code" } ] } [/block] with [block:code] { "codes": [ { "code": "ad.startTrackingView(<AD_CONTAINER_VIEW_GROUP>, withViewController:<CONTROLLER>)", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "[ad startTrackingView:<AD_CONTAINER_VIEW_GROUP> withViewController:<CONTROLLER>];", "language": "objectivec" } ] } [/block] You can also set up a listener on the model to listen for callbacks on the tracking process. [block:code] { "codes": [ { "code": "class YourClass: PNAdModelDelegate {\n//...\nmodel.delegate = self\n//...\nfunc pubantiveAdDidConfirmImpression(ad: PNAdModel!)\n{\n //Impression was just recorded\n}", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "@interface YourInterface () PNAdModelDelegate\n//...\nmodel.delegate = self;\n//...\n- (void)pubantiveAdDidConfirmImpression:(PubnativeAdModel *)ad\n{\n //Impression was just recorded\n}\n\n- (void)pubnativeAdDidClick:(PubnativeAdModel *)ad\n{\n //The ad was clicked, the ad will be opened right after this\n}", "language": "objectivec", "name": null } ] } [/block] You can find more about tracking ad view **[here](http://developers.pubnative.net/docs/native-ads#track-native-ad)**.