{"_id":"59a3dbe907e129001944cc05","project":"574ff4bd3fa1870e00889ba6","version":{"_id":"574ff4bd3fa1870e00889ba9","project":"574ff4bd3fa1870e00889ba6","__v":24,"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"],"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:29.754Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"This document facilitates the integration of PubNative iOS SDK.  There are four integration types for developers:\n* [Native Ads](http://developers.pubnative.net/docs/native-ads)\n* [Small Layout Ads](http://developers.pubnative.net/docs/small-ad-layouts)\n* [Medium Layout Ads](http://developers.pubnative.net/docs/medium-ad-layouts-1) \n* [Large Layout Ads](http://developers.pubnative.net/docs/large-ad-layouts-1)\n[block:api-header]\n{\n  \"title\": \"Requirements\"\n}\n[/block]\n* iOS 9.0+ (Base SDK supports 8.0 and up. Full-featured SDK supports 9.0 and up.)\n* An App Token provided in PubNative Dashboard\n* A Placement Name configured and obtained from the PubNative Dashboard\n[block:api-header]\n{\n  \"title\": \"Install Pubnative SDK\"\n}\n[/block]\n* [Download](https://github.com/pubnative/pubnative-ios-sdk/releases) **Pubnative.framework** and add it to your app. For this:\n\n1. Simply drag and drop the **Pubnative.framework** file to **Embedded Binaries** section on project configuration page.\n2. Select your target and navigate to the **Build Phases**. Then, add a **Run Script** step to your build steps.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/3c700a0-Screen_Shot_2017-10-24_at_09.55.16.png\",\n        \"Screen Shot 2017-10-24 at 09.55.16.png\",\n        811,\n        227,\n        \"#eaebeb\"\n      ]\n    }\n  ]\n}\n[/block]\n3. Put it after your step to Embed Frameworks, set it to use `/bin/sh` and enter the following script:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"APP_PATH=\\\"${TARGET_BUILD_DIR}/${WRAPPER_NAME}\\\"\\n\\nfind \\\"$APP_PATH\\\" -name 'Pubnative.framework' -type d | while read -r FRAMEWORK\\ndo\\n    FRAMEWORK_EXECUTABLE_NAME=$(defaults read \\\"$FRAMEWORK/Info.plist\\\" CFBundleExecutable)\\n    FRAMEWORK_EXECUTABLE_PATH=\\\"$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME\\\"\\n    echo \\\"Executable is $FRAMEWORK_EXECUTABLE_PATH\\\"\\n\\n    EXTRACTED_ARCHS=()\\n\\n    for ARCH in $ARCHS\\n    do\\n        echo \\\"Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME\\\"\\n        lipo -extract \\\"$ARCH\\\" \\\"$FRAMEWORK_EXECUTABLE_PATH\\\" -o \\\"$FRAMEWORK_EXECUTABLE_PATH-$ARCH\\\"\\n        EXTRACTED_ARCHS+=(\\\"$FRAMEWORK_EXECUTABLE_PATH-$ARCH\\\")\\n    done\\n\\n    echo \\\"Merging extracted architectures: ${ARCHS}\\\"\\n    lipo -o \\\"$FRAMEWORK_EXECUTABLE_PATH-merged\\\" -create \\\"${EXTRACTED_ARCHS[:::at:::]}\\\"\\n    rm \\\"${EXTRACTED_ARCHS[@]}\\\"\\n\\n    echo \\\"Replacing original executable with thinned version\\\"\\n    rm \\\"$FRAMEWORK_EXECUTABLE_PATH\\\"\\n    mv \\\"$FRAMEWORK_EXECUTABLE_PATH-merged\\\" \\\"$FRAMEWORK_EXECUTABLE_PATH\\\"\\n\\ndone\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Configure the iOS SDK\"\n}\n[/block]\nThere are certain parameters that should be configured in the SDK before doing any type of interaction with it. Ensure to configure these parameters only 1 per session.\n\n**If your app is COPPA compliant:** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Pubnative.setCoppaMode(Bool)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Pubnative setCoppa:BOOL];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n**Targeting**\n\nIf you want to improve targeting, first configure the **PNAdTargetingModel** object that you want to pass on and then invoke the following method:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var targeting = PNAdTargetingModel()\\ntargeting.age = <AGE>\\ntargeting.education = \\\"<EDUCATION>\\\"\\ntargeting.interests = <ARRAY_OF_THE_INTERESTS>\\ntargeting.gender = \\\"<GENDER>\\\"     // \\\"F\\\" for female, \\\"M\\\" for male\\nPubnative.setTargeting(targeting)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PNAdTargetingModel *targeting = [[PNAdTargetingModel alloc] init];\\ntargeting.age = <AGE>;\\ntargeting.education = \\\"<EDUCATION>\\\";\\ntargeting.interests = <ARRAY_OF_THE_INTERESTS>;\\ntargeting.gender = \\\"<GENDER>\\\";     // \\\"F\\\" for female, \\\"M\\\" for male\\n[Pubnative setTargeting:targeting];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n**Test Mode**\n\nIn development, you should set Test Mode as **`true`** for our SDK and disable it in the release. It allows not to track impressions and tracks on the server side of development application:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Pubnative.setTestMode(Bool)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Pubnative setTestMode:BOOL];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n**Initialise SDK**\n\nAdd the **PubNative.framework** to your code.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import Pubnative\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#import <Pubnative/Pubnative.h>\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nIn order to initialize a request, you must call `init()` before requesting for ads.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Pubnative.initWithAppToken(\\\"<YOUR_APP_TOKEN_HERE>\\\")\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Pubnative initWithAppToken:@\\\"<YOUR_APP_TOKEN_HERE>\\\"];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"PubNative iOS SDK Integration Samples\"\n}\n[/block]\nFor more integration examples, refer to our [PubNative iOS SDK Integration Samples](https://github.com/pubnative/pubnative-ios-integration-examples). You can find common integration scenarios such as:\n\n* Native Ad\n* Small Layout Ad\n* Medium Layout Ad\n* Large Layout Ad\n* Targeting Ad\n* Refreshing Ad\n* In-Feed Ad","excerpt":"","slug":"for-developers-1","type":"basic","title":"For Developers"}
This document facilitates the integration of PubNative iOS SDK. There are four integration types for developers: * [Native Ads](http://developers.pubnative.net/docs/native-ads) * [Small Layout Ads](http://developers.pubnative.net/docs/small-ad-layouts) * [Medium Layout Ads](http://developers.pubnative.net/docs/medium-ad-layouts-1) * [Large Layout Ads](http://developers.pubnative.net/docs/large-ad-layouts-1) [block:api-header] { "title": "Requirements" } [/block] * iOS 9.0+ (Base SDK supports 8.0 and up. Full-featured SDK supports 9.0 and up.) * An App Token provided in PubNative Dashboard * A Placement Name configured and obtained from the PubNative Dashboard [block:api-header] { "title": "Install Pubnative SDK" } [/block] * [Download](https://github.com/pubnative/pubnative-ios-sdk/releases) **Pubnative.framework** and add it to your app. For this: 1. Simply drag and drop the **Pubnative.framework** file to **Embedded Binaries** section on project configuration page. 2. Select your target and navigate to the **Build Phases**. Then, add a **Run Script** step to your build steps. [block:image] { "images": [ { "image": [ "https://files.readme.io/3c700a0-Screen_Shot_2017-10-24_at_09.55.16.png", "Screen Shot 2017-10-24 at 09.55.16.png", 811, 227, "#eaebeb" ] } ] } [/block] 3. Put it after your step to Embed Frameworks, set it to use `/bin/sh` and enter the following script: [block:code] { "codes": [ { "code": "APP_PATH=\"${TARGET_BUILD_DIR}/${WRAPPER_NAME}\"\n\nfind \"$APP_PATH\" -name 'Pubnative.framework' -type d | while read -r FRAMEWORK\ndo\n FRAMEWORK_EXECUTABLE_NAME=$(defaults read \"$FRAMEWORK/Info.plist\" CFBundleExecutable)\n FRAMEWORK_EXECUTABLE_PATH=\"$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME\"\n echo \"Executable is $FRAMEWORK_EXECUTABLE_PATH\"\n\n EXTRACTED_ARCHS=()\n\n for ARCH in $ARCHS\n do\n echo \"Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME\"\n lipo -extract \"$ARCH\" \"$FRAMEWORK_EXECUTABLE_PATH\" -o \"$FRAMEWORK_EXECUTABLE_PATH-$ARCH\"\n EXTRACTED_ARCHS+=(\"$FRAMEWORK_EXECUTABLE_PATH-$ARCH\")\n done\n\n echo \"Merging extracted architectures: ${ARCHS}\"\n lipo -o \"$FRAMEWORK_EXECUTABLE_PATH-merged\" -create \"${EXTRACTED_ARCHS[@]}\"\n rm \"${EXTRACTED_ARCHS[@]}\"\n\n echo \"Replacing original executable with thinned version\"\n rm \"$FRAMEWORK_EXECUTABLE_PATH\"\n mv \"$FRAMEWORK_EXECUTABLE_PATH-merged\" \"$FRAMEWORK_EXECUTABLE_PATH\"\n\ndone", "language": "shell" } ] } [/block] [block:api-header] { "title": "Configure the iOS SDK" } [/block] There are certain parameters that should be configured in the SDK before doing any type of interaction with it. Ensure to configure these parameters only 1 per session. **If your app is COPPA compliant:** [block:code] { "codes": [ { "code": "Pubnative.setCoppaMode(Bool)", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "[Pubnative setCoppa:BOOL];", "language": "objectivec" } ] } [/block] **Targeting** If you want to improve targeting, first configure the **PNAdTargetingModel** object that you want to pass on and then invoke the following method: [block:code] { "codes": [ { "code": "var targeting = PNAdTargetingModel()\ntargeting.age = <AGE>\ntargeting.education = \"<EDUCATION>\"\ntargeting.interests = <ARRAY_OF_THE_INTERESTS>\ntargeting.gender = \"<GENDER>\" // \"F\" for female, \"M\" for male\nPubnative.setTargeting(targeting)", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "PNAdTargetingModel *targeting = [[PNAdTargetingModel alloc] init];\ntargeting.age = <AGE>;\ntargeting.education = \"<EDUCATION>\";\ntargeting.interests = <ARRAY_OF_THE_INTERESTS>;\ntargeting.gender = \"<GENDER>\"; // \"F\" for female, \"M\" for male\n[Pubnative setTargeting:targeting];", "language": "objectivec" } ] } [/block] **Test Mode** In development, you should set Test Mode as **`true`** for our SDK and disable it in the release. It allows not to track impressions and tracks on the server side of development application: [block:code] { "codes": [ { "code": "Pubnative.setTestMode(Bool)", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "[Pubnative setTestMode:BOOL];", "language": "objectivec" } ] } [/block] **Initialise SDK** Add the **PubNative.framework** to your code. [block:code] { "codes": [ { "code": "import Pubnative", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "#import <Pubnative/Pubnative.h>", "language": "objectivec" } ] } [/block] In order to initialize a request, you must call `init()` before requesting for ads. [block:code] { "codes": [ { "code": "Pubnative.initWithAppToken(\"<YOUR_APP_TOKEN_HERE>\")", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "[Pubnative initWithAppToken:@\"<YOUR_APP_TOKEN_HERE>\"];", "language": "objectivec" } ] } [/block] [block:api-header] { "title": "PubNative iOS SDK Integration Samples" } [/block] For more integration examples, refer to our [PubNative iOS SDK Integration Samples](https://github.com/pubnative/pubnative-ios-integration-examples). You can find common integration scenarios such as: * Native Ad * Small Layout Ad * Medium Layout Ad * Large Layout Ad * Targeting Ad * Refreshing Ad * In-Feed Ad