{"_id":"5a210ae78415d200120a93ec","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":"59a8129f1e7b26000fa0fb1a","project":"574ff4bd3fa1870e00889ba6","version":"574ff4bd3fa1870e00889ba9","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-08-31T13:43:59.109Z","from_sync":false,"order":12,"slug":"unity-sdk","title":"Unity SDK"},"user":"5770fa1ce5a0000e0023c680","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-12-01T07:55:19.057Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"PubNative Plugin for Unity supports 2 ad formats:\n\n  * **[Banner](http://developers.pubnative.net/v3.0/docs/ios-plugin-1#installation-instructions)**\n  * **[Interstitial](http://developers.pubnative.net/v3.0/docs/ios-plugin-1#interstitial-integration-instructions)**\n\nFor the moment only Android and iOS are supported by the plugin. The ads won’t display if built for any other platform.\n[block:api-header]\n{\n  \"title\": \"Installation instructions\"\n}\n[/block]\n# Requirements\n\n  * Unity Project (Minimum Unity 5)\n  * PubNative SDK. It can be found here: https://github.com/pubnative/pubnative-ios-sdk/releases/tag/2.0.1\n  * An **App token** provided by the PubNative dashboard\n  * A **Placement Name** created in the PubNative dashboard\n  * PubNative Unity Plugin. It can be found here: https://drive.google.com/file/d/1XDDMR6tMDlGhGmn4KWL2qrPfdt0OBOtg/view?usp=sharing\n\n# Plugin integration:\n\nOpen the project in the Unity Editor\nMake sure that the **Assets** folder is created inside the project folder.\nWith the project open, Copy and Paste the **Editor**, **Plugins** and **Scripts** folders with all the files inside of them into the **Assets** folder. (*You can dismiss the “Could not create texture from…...” errors that come up in the console.)*\n\nNow the plugin is integrated and ready to begin the specific integration per ad format. \n\n# Caution\n\nWhen you export your Unity Project into a Xcode project make sure to include this step below:\n\n  * Select your target and navigate to the **“Build Phases”**. Then, add a **Run Scrip**t step to your build steps. \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/dcd8a34-Screen_Shot_2017-12-01_at_10.42.17.png\",\n        \"Screen Shot 2017-12-01 at 10.42.17.png\",\n        604,\n        173,\n        \"#ebebeb\"\n      ]\n    }\n  ]\n}\n[/block]\n  * 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  * Do not forget to check your project’s *“Frameworks Search Paths”* in your Build Settings. Make sure that the path for **Pubnative.framework** is provided correctly.\n[block:api-header]\n{\n  \"title\": \"Banner integration instructions\"\n}\n[/block]\n# Creating the banner\n\nThe **PNBanner** should be created inside a script which is linked to a **GameObject**. It must be created using the PNBannerFactory **create** method which created a banner based on the platform that the application is being built for.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public static PNBanner createBanner(MonoBehaviour parent) \",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nA sample of this this instantiation is the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PNBanner banner = PNBannerFactory.createBanner (this);\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIn the previous sample **“this”** is an object which inherits from MonoBehaviour so it’s linked to a **GameObject**.\n\nAfter creating the banner you must set the **appToken** and **placement** properties:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"banner.appToken = “app token obtain from PubNative dashboard”;\\nbanner.placement = “placement name configured in dashboard”; \\n\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\nSetting the listeners is also recommended to check the correct behaviour of the ads. There are two listeners for **PNBanner**: **ILoadListener** and **ITrackListener**.\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public interface ILoadListener\\n{\\n    void OnLoadFinished ();\\n\\n    void OnLoadFailed (Exception error);\\n} \\n\\npublic interface ITrackListener\\n{\\n    void OnImpressionTracked ();\\n\\n    void OnClickTracked ();\\n} \\n\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nAdding a **LoadListener** to the **PNBanner** is mandatory since it will send callbacks when the ad was loaded or failed. After the ad is loaded then it can be displayed.\n\n**TrackListener** is optional in case you want to receive callbacks when the ad has been impressed on screen or when the ad has been clicked. \n\nHere’s an implementation sample:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"banner.LoadListener = LOAD_LISTENER_INSTANCE;\\nbanner.TrackListener = TRACK_LISTENER_INSTANCE; \",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n# Loading the banner\n\nTo load the banner you should use the method: **Load ()** must be invoked in the following way:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"banner.Load (); \",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nThe result of this method will be received in the **LoadListener** callbacks.\n\n# Showing the banner\n\nThe banner can be displayed in two positions of the screen: TOP, BOTTOM. After the ad is loaded successfully, the method **Show (Position position)** must be used to display the ad.\n\nHere’s are samples of how to show the banner on top or bottom of the screen.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"banner.Show (PNBanner.Position.TOP); \\nbanner.Show (PNBanner.Position.BOTTOM); \",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nKeep in mind this method should be called always after receiving confirmation that the ad was loaded successfully. Otherwise it’ll result in an error and nothing will be displayed.\n\n# Code sample\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using System;\\nusing System.Collections;\\nusing System.Collections.Generic;\\nusing UnityEngine;\\nusing UnityEngine.UI;\\n\\npublic class BannerNative : MonoBehaviour, ILoadListener, ITrackListener\\n{\\n    private PNBanner banner;\\n\\n    public string appToken;\\n    public string placement;\\n\\n    [SerializeField]\\n    private Button _buttonLoadBanner;\\n\\n    [SerializeField]\\n    private Button _buttonHideBanner;\\n\\n    // Use this for initialization\\n    void Start ()\\n    {\\n        banner = PNBannerFactory.createBanner (this);\\n\\n        banner.appToken = appToken;\\n        banner.placement = placement;\\n        banner.LoadListener = this;\\n        banner.TrackListener = this;\\n        _buttonLoadBanner.onClick.AddListener (RequestBanner);\\n        _buttonHideBanner.onClick.AddListener (HideBanner);\\n    }\\n\\n    private void RequestBanner ()\\n    {\\n        if (banner != null) {\\n            banner.Load ();\\n        }\\n    }\\n\\n    private void HideBanner ()\\n    {\\n        banner.Hide ();\\n    }\\n\\n    public void OnLoadFinished ()\\n    {\\n        banner.Show (PNBanner.Position.TOP);\\n    }\\n\\n    public void OnLoadFailed (Exception error)\\n    {\\n        // Handle error\\n    }\\n\\n    public void OnImpressionTracked()\\n    {\\n        // Handle Impression\\n    }\\n\\n    public void OnClickTracked ()\\n    {\\n        // Handle Click\\n    }\\n} \",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Interstitial integration instructions\"\n}\n[/block]\n# Creating the interstitial\n\nThe **PNInterstitial** should be created inside a script which is linked to a **GameObject**. It must be created using the PNInterstitialFactory **create** method which created a banner based on the platform that the application is being built for.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public static PNInterstitial createInterstitial(MonoBehaviour parent) \",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nA sample of this this instantiation is the following:\n\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PNInterstitial interstitial = PNInterstitialFactory.createInterstitial (this);  \",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIn the previous sample **“this”** is an object which inherits from MonoBehaviour so it’s linked to a **GameObject**.\n\nAfter creating the interstitial you must set the **appToken** and **placement** properties:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"interstitial.appToken = “app token obtain from PubNative dashboard”;\\ninterstitial.placement = “placement name configured in dashboard”; \",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nSetting the listeners is also recommended to check the correct behaviour of the ads. There are three listeners for **PNInterstitial**: **ILoadListener**, **ITrackListener** and **IViewListener**.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public interface ILoadListener\\n{\\n    void OnLoadFinished ();\\n\\n    void OnLoadFailed (Exception error);\\n} \\n\\npublic interface ITrackListener\\n{\\n    void OnImpressionTracked ();\\n\\n    void OnClickTracked ();\\n} \\n\\npublic interface IViewListener\\n{\\n    void OnShown ();\\n\\n    void OnHidden ();\\n} \\n\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nAdding a **LoadListener** to the **PNInterstitial** is mandatory since it will send callbacks when the ad was loaded or failed. After the ad is loaded then it can be displayed.\n\n**TrackListener** is optional in case you want to receive callbacks when the ad has been impressed on screen or when the ad has been clicked.\n\n**ViewListener** is optional in case you want to receive callbacks when the interstitial has been shown and hidden.\n\nHere’s an implementation sample:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"interstitial.LoadListener = LOAD_LISTENER_INSTANCE;\\ninterstitial.TrackListener = TRACK_LISTENER_INSTANCE; \\ninterstitial.ViewListener = VIEW_LISTENER_INSTANCE; \",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n# Loading the interstitial\n\nTo load the interstitial you should use the method: **Load ()** must be invoked in the following way:\n\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"interstitial.Load (); \",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nThe result of this method will be received in the **LoadListener** callbacks.\n\n# Showing the interstitial\n\nAfter the ad is loaded successfully, the method **Show ()** must be used to display the ad.\n\nHere’s are samples of how to show interstitial on screen.\n\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"interstitial.Show (); \",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nKeep in mind this method should be called always after receiving confirmation that the ad was loaded successfully. Otherwise it’ll result in an error and nothing will be displayed.\n\n# Code sample\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using System;\\nusing System.Collections;\\nusing System.Collections.Generic;\\nusing UnityEngine;\\nusing UnityEngine.UI;\\n\\npublic class InterstitialNative : MonoBehaviour, ILoadListener, ITrackListener, IViewListener\\n{\\n    private PNInterstitial interstitial;\\n\\n    public string appToken;\\n    public string placement;\\n\\n    [SerializeField]\\n    private Button _buttonLoadInterstitial;\\n\\n    // Use this for initialization\\n    void Start ()\\n    {\\n        interstitial = PNInterstitialFactory.createInterstitial (this);\\n\\n        interstitial.appToken = appToken;\\n        interstitial.placement = placement;\\n        interstitial.LoadListener = this;\\n        interstitial.TrackListener = this;\\n        interstitial.ViewListener = this;\\n        _buttonLoadInterstitial.onClick.AddListener (RequestInterstitial);\\n    }\\n\\n    private void RequestInterstitial ()\\n    {\\n        if (interstitial != null) {\\n            interstitial.Load();\\n        }\\n    }\\n\\n    public void OnLoadFinished ()\\n    {\\n        interstitial.Show ();\\n    }\\n\\n    public void OnLoadFailed (Exception error)\\n    {\\n        // Handle error\\n    }\\n\\n    public void OnImpressionTracked()\\n    {\\n        // Handle Impression\\n    }\\n\\n    public void OnClickTracked ()\\n    {\\n        // Handle Click\\n    }\\n\\n    public void OnShown ()\\n    {\\n        // Handle interstitial show\\n    }\\n\\n    public void OnHidden ()\\n    {\\n        // Handle interstitial hide\\n    }\\n}\\n\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Demo app\"\n}\n[/block]\nHere is [the demo project](https://drive.google.com/file/d/1XDDMR6tMDlGhGmn4KWL2qrPfdt0OBOtg/view?usp=sharing) for unity and the generated iOS project.","excerpt":"","slug":"ios-plugin-1","type":"basic","title":"iOS Plugin"}
PubNative Plugin for Unity supports 2 ad formats: * **[Banner](http://developers.pubnative.net/v3.0/docs/ios-plugin-1#installation-instructions)** * **[Interstitial](http://developers.pubnative.net/v3.0/docs/ios-plugin-1#interstitial-integration-instructions)** For the moment only Android and iOS are supported by the plugin. The ads won’t display if built for any other platform. [block:api-header] { "title": "Installation instructions" } [/block] # Requirements * Unity Project (Minimum Unity 5) * PubNative SDK. It can be found here: https://github.com/pubnative/pubnative-ios-sdk/releases/tag/2.0.1 * An **App token** provided by the PubNative dashboard * A **Placement Name** created in the PubNative dashboard * PubNative Unity Plugin. It can be found here: https://drive.google.com/file/d/1XDDMR6tMDlGhGmn4KWL2qrPfdt0OBOtg/view?usp=sharing # Plugin integration: Open the project in the Unity Editor Make sure that the **Assets** folder is created inside the project folder. With the project open, Copy and Paste the **Editor**, **Plugins** and **Scripts** folders with all the files inside of them into the **Assets** folder. (*You can dismiss the “Could not create texture from…...” errors that come up in the console.)* Now the plugin is integrated and ready to begin the specific integration per ad format. # Caution When you export your Unity Project into a Xcode project make sure to include this step below: * Select your target and navigate to the **“Build Phases”**. Then, add a **Run Scrip**t step to your build steps. [block:image] { "images": [ { "image": [ "https://files.readme.io/dcd8a34-Screen_Shot_2017-12-01_at_10.42.17.png", "Screen Shot 2017-12-01 at 10.42.17.png", 604, 173, "#ebebeb" ] } ] } [/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] * Do not forget to check your project’s *“Frameworks Search Paths”* in your Build Settings. Make sure that the path for **Pubnative.framework** is provided correctly. [block:api-header] { "title": "Banner integration instructions" } [/block] # Creating the banner The **PNBanner** should be created inside a script which is linked to a **GameObject**. It must be created using the PNBannerFactory **create** method which created a banner based on the platform that the application is being built for. [block:code] { "codes": [ { "code": "public static PNBanner createBanner(MonoBehaviour parent) ", "language": "shell" } ] } [/block] A sample of this this instantiation is the following: [block:code] { "codes": [ { "code": "PNBanner banner = PNBannerFactory.createBanner (this);", "language": "shell" } ] } [/block] In the previous sample **“this”** is an object which inherits from MonoBehaviour so it’s linked to a **GameObject**. After creating the banner you must set the **appToken** and **placement** properties: [block:code] { "codes": [ { "code": "banner.appToken = “app token obtain from PubNative dashboard”;\nbanner.placement = “placement name configured in dashboard”; \n", "language": "shell" } ] } [/block] Setting the listeners is also recommended to check the correct behaviour of the ads. There are two listeners for **PNBanner**: **ILoadListener** and **ITrackListener**. [block:code] { "codes": [ { "code": "public interface ILoadListener\n{\n void OnLoadFinished ();\n\n void OnLoadFailed (Exception error);\n} \n\npublic interface ITrackListener\n{\n void OnImpressionTracked ();\n\n void OnClickTracked ();\n} \n", "language": "shell" } ] } [/block] Adding a **LoadListener** to the **PNBanner** is mandatory since it will send callbacks when the ad was loaded or failed. After the ad is loaded then it can be displayed. **TrackListener** is optional in case you want to receive callbacks when the ad has been impressed on screen or when the ad has been clicked. Here’s an implementation sample: [block:code] { "codes": [ { "code": "banner.LoadListener = LOAD_LISTENER_INSTANCE;\nbanner.TrackListener = TRACK_LISTENER_INSTANCE; ", "language": "shell" } ] } [/block] # Loading the banner To load the banner you should use the method: **Load ()** must be invoked in the following way: [block:code] { "codes": [ { "code": "banner.Load (); ", "language": "shell" } ] } [/block] The result of this method will be received in the **LoadListener** callbacks. # Showing the banner The banner can be displayed in two positions of the screen: TOP, BOTTOM. After the ad is loaded successfully, the method **Show (Position position)** must be used to display the ad. Here’s are samples of how to show the banner on top or bottom of the screen. [block:code] { "codes": [ { "code": "banner.Show (PNBanner.Position.TOP); \nbanner.Show (PNBanner.Position.BOTTOM); ", "language": "shell" } ] } [/block] Keep in mind this method should be called always after receiving confirmation that the ad was loaded successfully. Otherwise it’ll result in an error and nothing will be displayed. # Code sample [block:code] { "codes": [ { "code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\nusing UnityEngine.UI;\n\npublic class BannerNative : MonoBehaviour, ILoadListener, ITrackListener\n{\n private PNBanner banner;\n\n public string appToken;\n public string placement;\n\n [SerializeField]\n private Button _buttonLoadBanner;\n\n [SerializeField]\n private Button _buttonHideBanner;\n\n // Use this for initialization\n void Start ()\n {\n banner = PNBannerFactory.createBanner (this);\n\n banner.appToken = appToken;\n banner.placement = placement;\n banner.LoadListener = this;\n banner.TrackListener = this;\n _buttonLoadBanner.onClick.AddListener (RequestBanner);\n _buttonHideBanner.onClick.AddListener (HideBanner);\n }\n\n private void RequestBanner ()\n {\n if (banner != null) {\n banner.Load ();\n }\n }\n\n private void HideBanner ()\n {\n banner.Hide ();\n }\n\n public void OnLoadFinished ()\n {\n banner.Show (PNBanner.Position.TOP);\n }\n\n public void OnLoadFailed (Exception error)\n {\n // Handle error\n }\n\n public void OnImpressionTracked()\n {\n // Handle Impression\n }\n\n public void OnClickTracked ()\n {\n // Handle Click\n }\n} ", "language": "shell" } ] } [/block] [block:api-header] { "title": "Interstitial integration instructions" } [/block] # Creating the interstitial The **PNInterstitial** should be created inside a script which is linked to a **GameObject**. It must be created using the PNInterstitialFactory **create** method which created a banner based on the platform that the application is being built for. [block:code] { "codes": [ { "code": "public static PNInterstitial createInterstitial(MonoBehaviour parent) ", "language": "shell" } ] } [/block] A sample of this this instantiation is the following: [block:code] { "codes": [ { "code": "PNInterstitial interstitial = PNInterstitialFactory.createInterstitial (this); ", "language": "shell" } ] } [/block] In the previous sample **“this”** is an object which inherits from MonoBehaviour so it’s linked to a **GameObject**. After creating the interstitial you must set the **appToken** and **placement** properties: [block:code] { "codes": [ { "code": "interstitial.appToken = “app token obtain from PubNative dashboard”;\ninterstitial.placement = “placement name configured in dashboard”; ", "language": "shell" } ] } [/block] Setting the listeners is also recommended to check the correct behaviour of the ads. There are three listeners for **PNInterstitial**: **ILoadListener**, **ITrackListener** and **IViewListener**. [block:code] { "codes": [ { "code": "public interface ILoadListener\n{\n void OnLoadFinished ();\n\n void OnLoadFailed (Exception error);\n} \n\npublic interface ITrackListener\n{\n void OnImpressionTracked ();\n\n void OnClickTracked ();\n} \n\npublic interface IViewListener\n{\n void OnShown ();\n\n void OnHidden ();\n} \n", "language": "shell" } ] } [/block] Adding a **LoadListener** to the **PNInterstitial** is mandatory since it will send callbacks when the ad was loaded or failed. After the ad is loaded then it can be displayed. **TrackListener** is optional in case you want to receive callbacks when the ad has been impressed on screen or when the ad has been clicked. **ViewListener** is optional in case you want to receive callbacks when the interstitial has been shown and hidden. Here’s an implementation sample: [block:code] { "codes": [ { "code": "interstitial.LoadListener = LOAD_LISTENER_INSTANCE;\ninterstitial.TrackListener = TRACK_LISTENER_INSTANCE; \ninterstitial.ViewListener = VIEW_LISTENER_INSTANCE; ", "language": "shell" } ] } [/block] # Loading the interstitial To load the interstitial you should use the method: **Load ()** must be invoked in the following way: [block:code] { "codes": [ { "code": "interstitial.Load (); ", "language": "shell" } ] } [/block] The result of this method will be received in the **LoadListener** callbacks. # Showing the interstitial After the ad is loaded successfully, the method **Show ()** must be used to display the ad. Here’s are samples of how to show interstitial on screen. [block:code] { "codes": [ { "code": "interstitial.Show (); ", "language": "shell" } ] } [/block] Keep in mind this method should be called always after receiving confirmation that the ad was loaded successfully. Otherwise it’ll result in an error and nothing will be displayed. # Code sample [block:code] { "codes": [ { "code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\nusing UnityEngine.UI;\n\npublic class InterstitialNative : MonoBehaviour, ILoadListener, ITrackListener, IViewListener\n{\n private PNInterstitial interstitial;\n\n public string appToken;\n public string placement;\n\n [SerializeField]\n private Button _buttonLoadInterstitial;\n\n // Use this for initialization\n void Start ()\n {\n interstitial = PNInterstitialFactory.createInterstitial (this);\n\n interstitial.appToken = appToken;\n interstitial.placement = placement;\n interstitial.LoadListener = this;\n interstitial.TrackListener = this;\n interstitial.ViewListener = this;\n _buttonLoadInterstitial.onClick.AddListener (RequestInterstitial);\n }\n\n private void RequestInterstitial ()\n {\n if (interstitial != null) {\n interstitial.Load();\n }\n }\n\n public void OnLoadFinished ()\n {\n interstitial.Show ();\n }\n\n public void OnLoadFailed (Exception error)\n {\n // Handle error\n }\n\n public void OnImpressionTracked()\n {\n // Handle Impression\n }\n\n public void OnClickTracked ()\n {\n // Handle Click\n }\n\n public void OnShown ()\n {\n // Handle interstitial show\n }\n\n public void OnHidden ()\n {\n // Handle interstitial hide\n }\n}\n", "language": "shell" } ] } [/block] [block:api-header] { "title": "Demo app" } [/block] Here is [the demo project](https://drive.google.com/file/d/1XDDMR6tMDlGhGmn4KWL2qrPfdt0OBOtg/view?usp=sharing) for unity and the generated iOS project.