抖音合作 SDK 接入指南
添加 SDK
- Unity
- UE
- XDSDK 6.23.1 或更高
- ADS 3.6.1 或更高
{
"dependencies": {
"com.xd.sdk.douyincps": "1.0.1",
},
"scopedRegistries": [
{
// NPMJS 访问不通时可以切换到淘宝源试试 https://registry.npmmirror.com
// 公司内网可使用 http://npm.xindong.com
"name": "NPMJS",
"url": "https://registry.npmjs.org/",
"scopes": [
"com.xd",
"com.tapsdk",
"com.leancloud"
]
}
]
}
- XDSDK 6.28.3 或更高
勾选 XDGDouYinCPS 模块
添加配置文件
请联系平台同事获取 iOS(UOPSDKConfig.json) 和 Android(config.json) 的配置文件
- Unity
- UE
按照如下结构将文件放在指定的文件夹内,SDK 会自动拷贝配置到最终产物中。
project-root/
│
└─ Assets/
└─ Plugins/
├─ Android/
│ └─ config.json
│
└─ iOS/
└─ UOPSDKConfig.json
UE 请自行写脚本将两份配置文件拷贝到对应平台产物中。可参考以下示例:
<root>
<resourceCopies>
// Android
<copyDir src="$S(PluginDir)/XDConfigs/config.json" dst="$S(BuildDir)/assets"/>
// iOS
<copyDir src="$S(PluginDir)/XDConfigs/UOPSDKConfig.json" dst="$S(BuildDir)/"/>
</resourceCopies>
</root>
添加配置支持从抖音拉起游戏
Android Manifest 配置
抖音打开游戏功能会通过 scheme 拉起游戏。Android 则需要游戏侧增加相应 Activity 配置以响应该scheme。参考格式如下:
- com.xxx.GameLaunchActivity 为游戏的主 Activity(Unity:
com.unity3d.player.UnityPlayerActivity
; UE:com/epicgames/ue4/GameActivity
) - "android:exported" 必须设置为 true
- ${applicationId} 不需要修改
- dygame{appId} 中的
{appId}
需要替换为前文拿到的 config.json 中的 app_id
<activity
android:name="com.xxx.GameLaunchActivity"
android:exported="true"
android:launchMode="singleTask"
android:taskAffinity="${applicationId}">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="${applicationId}"
android:path="/jump_to_game"
android:scheme="dygame{appId}" />
</intent-filter>
</activity>
UE 可参考以下实例添加 AndroidManifest 配置:
<root>
<androidManifestUpdates>
<loopElements tag="activity">
<setStringFromAttribute result="activityName" tag="$" name="android:name" />
<setBoolIsEqual result="bResultActivity" arg1="$S(activityName)" arg2="com.epicgames.ue4.GameActivity"/>
<if condition="bResultActivity">
<true>
<setElement result="IntentFilterKey" value="intent-filter"/>
<setElement result="DataIDKey" value="data"/>
<addAttribute tag="$DataIDKey" name="android:host" value="${applicationId}"/>
<addAttribute tag="$DataIDKey" name="android:path" value="/jump_to_game"/>
<addAttribute tag="$DataIDKey" name="android:scheme" value="dygame{appId}"/> <!-- 替换真实的 appId -->
<addElement tag="$IntentFilterKey" name="DataIDKey"/>
<setElement result="ActionIDKey" value="action"/>
<addAttribute tag="$ActionIDKey" name="android:name" value="android.intent.action.VIEW"/>
<addElement tag="$IntentFilterKey" name="ActionIDKey"/>
<setElement result="CategoryIDKey1" value="category"/>
<addAttribute tag="$CategoryIDKey1" name="android:name" value="android.intent.category.DEFAULT"/>
<addElement tag="$IntentFilterKey" name="CategoryIDKey1"/>
<setElement result="CategoryIDKey2" value="category"/>
<addAttribute tag="$CategoryIDKey2" name="android:name" value="android.intent.category.BROWSABLE"/>
<addElement tag="$IntentFilterKey" name="CategoryIDKey2"/>
<addElement tag="$" name="IntentFilterKey"/>
</true>
</if>
</loopElements>
</androidManifestUpdates>
</root>
iOS Info.plist 配置
Unity SDK 会自动配置 iOS 的 Info.plist。 UE 请自行配置 Info.plist 文件,参考以下内容,
- dygame{appId} 中的
{appId}
需要替换为前文拿到的 UOPSDKConfig.json 中的 app_id
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>douyincps</string>
<key>CFBundleURLSchemes</key>
<array>
<string>dygame{appId}</string>
</array>
</dict>
验收
完成上述操作并成功出包后请联系平台同事进行验收。