Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

chinese_sdk_ios_integration_guide

Solomon Li edited this page Aug 19, 2016 · 8 revisions

Unity Ads SDK 2.0 - iOS Integration Guide

here有一个iOS集成示例.

如果是从 SDK 1.5.x 升级的话, 可以参考 iOS transition guide.

在下边的例子里, 我们会使用 Swift 并且只在 ViewController 里实现必须的方法.

  1. 从 Github 下载 最新的发布包 , 名字如 UnityAds.framework.zip.
  • 在 XCode 中打开已有的 iOS 项目或者创建一个新的.
  • 解压zip文件并将 UnityAds.framework 拖入项目中.
  • 在 ViewController 中导入 Unity Ads 包 import UnityAds.
  • 使 ViewController 实现 UnityAdsDelegate 协议 :
    class ViewController: UIViewController, UnityAdsDelegate
  • 在 ViewController 中实现如下协议中的方法 :
  • func unityAdsReady(placementId: String) {}
  • func unityAdsDidStart(placementId: String) {}
  • func unityAdsDidError(error: UnityAdsError, withMessage message: String) {}
  • func unityAdsDidFinish(placementId: String, withFinishState state: UnityAdsFinishState) {}
  • 调用 UnityAds.initialize(gameId, delegate: self) 初始化 Unity Ads SDK 2.0 . 其中 gameId 需要使用 string 类型, 可以在 Unity Ads dashboard 上的 iOS 平台下找到.
    Note: Unity Ads 只初始化一次. SDK 2.0 的网络重连功能更加可靠. 您可以在没有网络连接的情况下尝试初始化, 之后 SDK 会在网络可用的时候再请求广告.
  • 下面这段代码会展示一个默认(default)广告位的广告: if (UnityAds.isReady()) { UnityAds.show(self) }

Unity Ads SDK 2.0 在任何一次调用展示(show)方法时候, 都需要传入一个 ViewController 作为参数 (如上面示例中的self ).

更多信息请参考 Unity Ads iOS API 文档. 也可以参考 示例应用 来了解如何在您的项目中集成 Unity Ads.

Clone this wiki locally