Skip to content

fritzhuie/Unity-Ads-Swift-Example

Repository files navigation

This is an example project for implementing the Unity Ads SDK in a SpriteKit game using Swift

Planet illustration provided by NASA - Original image by ESA/Hubble (M. Kornmesser) - https://www.spacetelescope.org/

#How to integrate Unity Ads into your project

Import the Unity Ads Framework

  1. Download the Unity SDK from https://github.com/Applifier/unity-ads-sdk
  • Down the zip file
  • Unzip the project, and locate UnityAds.framework and UnityAds.bundle
  1. Import UnityAds.framework and UnityAds.bundle into your project
  • Drag and drop the files into your project
  • Select the box next to "Copy
  1. Make sure all of the following dependancies are enabled in your project

CoreMedia.framework, CoreTelephony.framework,

SystemConfiguration.framework, AdSupport.framework,

CFNetwork.framework, StoreKit.framework

  1. Add a bridging header for UnityAds.framework

####In Your AppDelegate:

  • Create a shared instance of Unity ads
static let unityAds = UnityAds()

####In Your Root View Controller

  • Initialize the SDK
UnityAds.sharedInstance().startWithGameId("YOUR_GAME_ID", andViewController: self)
  • Implement unityAdsVideoCompleted callback
func unityAdsVideoCompleted(rewardItemKey: String!, skipped: Bool) {if (!skipped) {//Provide ingame reward}}
  • Implement a method for displaying ads
UnityAds.sharedInstance().canShowZone(placement)) { UnityAds.sharedInstance().show() )

####In Your SKScene or Any ViewController

  • Call for a rewarded ad
let vc = self.view!.window!.rootViewController as! YourRootViewController vc.playAd("rewardedVideo")

About

Unity Ads example in Swift-SpriteKit

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published