IMPORTANT NOTE FOR IOS 9 PUBLISHERS
Apple is introducing App Transport Security in iOS 9. Please read our App Transport FAQ to understand more about this feature and steps you need to take to ensure a successful implementation
The release version of the NativeX iOS SDK has Bitcode enabled. If you require a version that has Bitcode disabled, please contact us for an alternate version.
Before You Begin
- Login/ Register to the NativeX Self Service site and add your app.
- Note: Our iOS SDK supports iOS 7, 8, 9 and 10.
- You will need to get your uniquely assigned NativeX AppID. (This is not the Apple ID. The AppID is required in order to identify you are paid correctly.) Once you have added your app(s), go to the App Manager. The AppID is located directly to the right of your app name in the App ID column.
1. Download the NativeX iOS SDK
- Download the NativeX iOS SDK .
- Unzip it.
2. Add the NativeX iOS SDK to your project
- Click and drag the NativeX iOS SDK folder into the project navigation bar of your project in XCode:
- Within the “Choose options for adding these files” dialog box, select the checkbox next to “Copy items into destination group’s folder”:
3. Add Required Frameworks and Settings
Within the project’s main window:
- Select your project’s Application Target or double-click the project under the PROJECT header.
- Select the Build Phases tab
- Within the ‘Link Binary with Libraries‘ section, add the following frameworks (if not already present):
- (iOS 9 and above) Disable App Transport Security
To disable App Transport Security, you will need to set a couple keys in your app’s info.plist file:
- In your app target, click on “Info” at the top, then right-click on the list and select “Add Row”
- In the row that appears, type “NSAppTransportSecurity”, and change the type to “Dictionary”
- Expand that new “NSAppTransportSecurity” key (arrow next to name should point down), right-click that key and select “Add Row”; new row should be a child of the “NSAppTransportSecurity” key
- Name that new child row “NSAllowsArbitraryLoads”; set the type to “Boolean”, and set it’s value to “YES”
Afterwards, the keys should look like this:
For more information about App Transport Security, including other methods for disabling and other options, see our App Transport Security FAQ.
- Try to build and run the app. You should receive no build errors at this time.
- Common Build Issues.
- Apple Mach-O Linker Error
- Bitcode Support
When archiving your app for submitting to the app store under XCode 7, you may see the following error:
The version of the NativeX iOS SDK distributed doesn’t come with bitcode support enabled by default. If your app doesn’t need to support bitcode builds, we suggest turning it off in your app (Select your Project > Select Target > Build Settings, search for “Bitcode” and set the value to NO).
if you do want to support bitcode we can supply a bitcode-enabled build for you; please contact support on http://nativexselfservice.uservoice.com/ for more information.
- Apple Mach-O Linker Error
4. Initialize the SDK
For those of you who don’t read documentation, Click here for a complete example of a Game Launch Ad Placement within the main AppDelegate.m file.
a. Import the NativeXSDK.h class file:
Copy & paste this line below the other import statements in the AppDelegate.h file
b. Initialize the SDK with your NativeX AppID
If you haven’t already, it’s time to set up an app through the NativeX Self Service site.
Your NativeX AppID can be found after setting up your app. It is displayed during the app setup process and you can always find it on the NativeX Self Service App Manager.
Insert the following lines in the AppDelegate.m file:
For publishers that have their own User IDs it is recommended that they use the following method for better tracking:
C. Run the App.
Run the app; you should see something similar to below in your console log:
Great! Your app is now talking to NativeX. It’s time to show some ads.
5. Show an Ad
So close! Remember to add NativeX SDK import statements (e.g. #import “NativeXSDK.h”) to code files you use so XCode doesn’t get mad at you.
a. Set up a Reward.
- Go to the Monetization Manager in the NativeX Self Service portal.
- Choose the app you want to add a reward for.
- Click the ‘Define Rewards’ tab.
- Enter the name of your reward (Reward Name).
- Enter the reward exchange rate (Reward Value Exchange), which is how much of the reward is equal to a dollar. Typically people will use their in-app purchase exchange rates as a guide.
- Enter the amount you would like to reward the user when they see a video ad (Video Ad Reward).
- Click ‘Save’
b. Configure a Rewarded Video Placement.
Make sure you remember which placement you created. The following code examples assume you’ve created a Game Launch placement.
- Go to the Monetization Manager in the NativeX Self Service Portal
- Choose the app you want to add a rewarded placement for
- Click ‘Add Placement’
- Choose the placement category. Try ‘Level Completed’
- Select ‘Rewarded’
- Change the placement to be rewarded
- Click Save
WARNING: After setting up a new placement, there is a 15 minute delay until you will receive the new ad when fetched.
c. Fetch the ad.
Fetching the ad allows the SDK to prepare the ad ahead of time – allowing your app to instantly show an ad to a user when you want. NativeX recommends you fetch an ad at one logical stopping point in the game prior to where you want to show the ad. For example, if you want to an ad at level complete, fetch the ad at level start or in the middle of the level. For Game Launch placements like the example we’re using, you can instruct the SDK to fetch the ad immediately, which will happen when the SDK finishes initializing:
d. Show the ad!
Add the following code, using the placement you got from step (b):
The “showAdWithPlacement:” and “showAdWithName:” methods return a boolean as to whether the ad was ready to be shown when the call is made; it will return YES if it will show immediately, and NO if it is not ready to show. In a real-world example, these methods should only be called after the ad has finished fetching from NativeX’s servers. “isAdFetchedWithPlacement:” and “isAdFetchedWithName:” are methods that allow you to check if an ad placement is ready before you call these show methods. These “isAdReady” methods return a boolean depending if the ad is fetched and is ready to be shown.
Remember to change which placement you’re using based on what kind of ad you want to show and where you’re showing it in the game. For example, if you want to show a video when a user opens your store, configure the Store Open placement and use the kAdPlacementStoreOpen placement in code.
Common Show Ad issues
If you get an “Another ad is already being presented” or “UIViewcontroller.presentedViewController is not nil” error messages when calling showAd when an ad is not actually showing, it likely is due to a different view is showing modally from the View controller that the SDK is using. The NativeX iOS SDK uses the UIViewController’s presentViewController:animated:completion: method to display the ad modally; if another view is already displayed modally using that method, the SDK will not replace that view and return that error. Either dismiss the current modal view, or use a different UIViewController as the “root” of the ad that will be displayed
e. Check for Rewards
The rewards that you configured in step 5a and are awarded to your user are automatically collected and stored within the SDK. Use the following code to check and collect any rewards that may have been given:
a. See our Advanced Integration Topics for some additional topics like debugging, delegates and handling audio for video ads!
b. If you’re upgrading to the new iOS SDK interface from the v5.x version, see Converting SDK 5.x to New Interface for additional documentation.
c. For ads that link to your in-app purchase store, please contact our support team at http://nativexselfservice.uservoice.com/.