{"_id":"59a3dbe907e129001944cc05","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: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](http://developers.pubnative.net/v3.0/docs/native-ads)\n* [Small Ad Layout](http://developers.pubnative.net/v3.0/docs/small-ad-layouts)\n* [Medium Ad Layout](http://developers.pubnative.net/v3.0/docs/medium-ad-layouts-1) \n* [Large Ad Layout](http://developers.pubnative.net/v3.0/docs/large-ad-layouts-1)\n[block:api-header]\n{\n  \"title\": \"Requirements\"\n}\n[/block]\n  * iOS 9.0+\n  * An App Token provided in PubNative Dashboard.\n  * A Placement Name configured in the PubNative Dashboard\n\n[block:api-header]\n{\n  \"title\": \"Install Pubnative SDK\"\n}\n[/block]\nThere are 2 ways to integrate our iOS SDK:\n  * [Drag'n'drop **Pubnative.framework**](http://developers.pubnative.net/v3.0/docs/for-developers-1#dragndrop-pubnativeframework)\n  * [Drag'n'drop folder **sdk/sdk** ](http://developers.pubnative.net/v3.0/docs/for-developers-1#dragndrop-folder-sdksdk)\n[block:api-header]\n{\n  \"title\": \"Drag'n'drop Pubnative.framework\"\n}\n[/block]\nDownload **Pubnative.framework** file and add it into your app. For this, simply drag'n'drop framework file to **Embedded Binaries** on project configuration page.\n\nSelect your target and navigate to the **“Build Phases”**. Then, add a **Run Script** step to your build steps.\n\n \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]\nPut it after your step to embed frameworks, set it to use /bin/sh and enter the following script:\n\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\": \"Drag'n'drop folder sdk/sdk\"\n}\n[/block]\nIf you are using iOS version below the 8, you still can integrate our SDK inside your project, but manualy by cloning the repository and drag'n'drop folder **sdk/sdk** into your app (be sure to check the \"Copy items into destination group's folder\" option).\n[block:api-header]\n{\n  \"title\": \"Configure 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(boolean)\",\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**Add Targeting**\n\nIf you want to improve targeting, first configure the PNAdTargetingModel object that you want to give away 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\nFor development mode, you should setup TestMode as true for our SDK and disable it in a release. It allows do not track impressions and tracks on the server side from 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\nIn order to initialize 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\": \"Integration samples project (TO ADD)\"\n}\n[/block]\nHere you can find a collection of most common pubnative SDK [integration examples for iOS]:\n\nCommon integration examples are:\n  * **[Native (PNRequest)](https://github.com/pubnative/pubnative-ios-integration-examples/pull/4)**\n  * **[Small Layout](https://github.com/pubnative/pubnative-ios-integration-examples/pull/1)**\n  * **[Medium Layout](https://github.com/pubnative/pubnative-ios-integration-examples/pull/3)**\n  * **[Large Layout](https://github.com/pubnative/pubnative-ios-integration-examples/pull/2)**","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](http://developers.pubnative.net/v3.0/docs/native-ads) * [Small Ad Layout](http://developers.pubnative.net/v3.0/docs/small-ad-layouts) * [Medium Ad Layout](http://developers.pubnative.net/v3.0/docs/medium-ad-layouts-1) * [Large Ad Layout](http://developers.pubnative.net/v3.0/docs/large-ad-layouts-1) [block:api-header] { "title": "Requirements" } [/block] * iOS 9.0+ * An App Token provided in PubNative Dashboard. * A Placement Name configured in the PubNative Dashboard [block:api-header] { "title": "Install Pubnative SDK" } [/block] There are 2 ways to integrate our iOS SDK: * [Drag'n'drop **Pubnative.framework**](http://developers.pubnative.net/v3.0/docs/for-developers-1#dragndrop-pubnativeframework) * [Drag'n'drop folder **sdk/sdk** ](http://developers.pubnative.net/v3.0/docs/for-developers-1#dragndrop-folder-sdksdk) [block:api-header] { "title": "Drag'n'drop Pubnative.framework" } [/block] Download **Pubnative.framework** file and add it into your app. For this, simply drag'n'drop framework file to **Embedded Binaries** on project configuration page. 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] 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": "Drag'n'drop folder sdk/sdk" } [/block] If you are using iOS version below the 8, you still can integrate our SDK inside your project, but manualy by cloning the repository and drag'n'drop folder **sdk/sdk** into your app (be sure to check the "Copy items into destination group's folder" option). [block:api-header] { "title": "Configure 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(boolean)", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "[Pubnative setCoppa:BOOL];", "language": "objectivec" } ] } [/block] **Add Targeting** If you want to improve targeting, first configure the PNAdTargetingModel object that you want to give away 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** For development mode, you should setup TestMode as true for our SDK and disable it in a release. It allows do not track impressions and tracks on the server side from development application: [block:code] { "codes": [ { "code": "Pubnative.setTestMode(BOOL)", "language": "swift" } ] } [/block] [block:code] { "codes": [ { "code": "[Pubnative setTestMode:BOOL];", "language": "objectivec" } ] } [/block] **Initialise SDK** In order to initialize 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": "Integration samples project (TO ADD)" } [/block] Here you can find a collection of most common pubnative SDK [integration examples for iOS]: Common integration examples are: * **[Native (PNRequest)](https://github.com/pubnative/pubnative-ios-integration-examples/pull/4)** * **[Small Layout](https://github.com/pubnative/pubnative-ios-integration-examples/pull/1)** * **[Medium Layout](https://github.com/pubnative/pubnative-ios-integration-examples/pull/3)** * **[Large Layout](https://github.com/pubnative/pubnative-ios-integration-examples/pull/2)**