iOS壳包接入头条+抖音cps
<p>[TOC]</p>
<h3>1、SDK资源引入</h3>
<pre><code>//可混淆修改
LewanSDK.h
LewanSDK.m
AES256.h
AES256.m
//头条 SDK
BDASignalDefinitions
libBDASignalSDK
//BUGLY SDK
Bugly.framework
//抖音 cps SDK
DYCPS 文件夹
//抖音配置文件
UOPSDKConfig.json
//隐私文件 按需合并自身已有
PrivacyInfo.xcprivacy</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=7315f2db2a82c9eaf477e365cc54217e&amp;file=file.png" alt="" /></p>
<ul>
<li>引入后配置如下图</li>
</ul>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=a25470977ed558f5dcad6f896fe0a6b4&amp;file=file.png" alt="" /></p>
<p>[抖音官方文档](<a href="https://game.open.douyin.com/platform/subapp/live/learning_center/detail/doc/?id=188&tab=X4g4fKRNtlzPddd3CPkcR2PBnKh&versions=2PdQgQ">https://game.open.douyin.com/platform/subapp/live/learning_center/detail/doc/?id=188&tab=X4g4fKRNtlzPddd3CPkcR2PBnKh&versions=2PdQgQ</a> "抖音官方文档")</p>
<ul>
<li>补充系统依赖</li>
</ul>
<pre><code>UIKit.framework
Foundation.framework
ApptrackingTransparency.framework (Optional, iOS14+)
Accelerate.framework
MobileCoreServices.framework</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=938d9a8834f334a39ccbb217c5ea2e82&amp;file=file.png" alt="" /></p>
<ul>
<li>若需要支持 iOS14 以下的系统,需要在 Build Phases -> Link Binary With Libraries 中将 ApptrackingTransparency.framework 设置为可选</li>
<li> 在 Build Settings -> Linking -> Other Linker Flags 添加 -ObjC,注意区分大小写</li>
</ul>
<h3>1.1、工程其他配置</h3>
<ul>
<li>
<p>保证抖音授权功能正常调起</p>
</li>
<li>Info.plist 配置 LSApplicationQueriesSchemes</li>
</ul>
<pre><code>douyinopensdk
douyinsharesdk
snssdk1128
douyinv1opensdk
douyinliteopensdk</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=1c5f2aa6f98e634436d5f1f64deea3f7&amp;file=file.png" alt="" /></p>
<ul>
<li>配置URL Schemes</li>
</ul>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=393ed24a4d0945c9e3b898befe2cda86&amp;file=file.png" alt="" /></p>
<p>[以上配置抖音官方文档](<a href="https://bytedance.larkoffice.com/wiki/GpUWw0scsiz86ck2o2ZcV1Q7nqe">https://bytedance.larkoffice.com/wiki/GpUWw0scsiz86ck2o2ZcV1Q7nqe</a> "以上配置抖音官方文档")</p>
<h3>2、接口说明</h3>
<h4>2.1、客户端启动上报接口( 生命周期)</h4>
<pre><code>#import &quot;LewanSDK.h&quot;
如使用AppDelegate</code></pre>
<pre><code class="language-objectivec">- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[LewanSDK getInstance] application:application didFinishLaunchingWithOptions:launchOptions];
return YES;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary&lt;UIApplicationOpenURLOptionsKey,id&gt; *)options{
[[LewanSDK getInstance] application:app openURL:url options:options];
return YES;
}</code></pre>
<pre><code>如使用SceneDelegate</code></pre>
<pre><code class="language-objectivec">- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
[[LewanSDK getInstance] scene:scene willConnectToSession:session options:connectionOptions];
}
- (void)scene:(UIScene *)scene openURLContexts:(NSSet&lt;UIOpenURLContext *&gt; *)URLContexts{
[[LewanSDK getInstance] scene:scene openURLContexts:URLContexts];
}</code></pre>
<h4>2.2、SDK 初始化</h4>
<ul>
<li>在 H5 游戏界面 WKWebView中调用</li>
</ul>
<pre><code> [[LewanSDK getInstance] setupSDK:self];//初始化
[[LewanSDK getInstance] setPageView:WKWebView];//传入 webview 用于交互
//封装旧激活上报代码,如已接入旧的代码可不调用(即 3、客户端上报激活代码demo )
[[LewanSDK getInstance] gameActive];</code></pre>
<h4>2.3、注册交互监听</h4>
<ul>
<li>在 H5游戏界面 WKWebView 初始化中设置 <code>iosWebView</code>(必须)</li>
</ul>
<pre><code> WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc]init];
[config.userContentController addScriptMessageHandler:self name:@&quot;iosWebView&quot;];
//webview 初始化传入,或其他方式传入 iosWebView 即可</code></pre>
<ul>
<li>在WKScriptMessageHandler中调用</li>
</ul>
<pre><code>- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
[[LewanSDK getInstance] userContentController:userContentController didReceiveScriptMessage:message];
}</code></pre>