DeepLink 设置方式
本文档介绍在应用内设置与网页游览器 "myapp://" 上的 Deep Link URL 相同。可以达到直接启动应用的效果。
为了正常使用 IGAWorks 服务上的 DeepLink 功能,请确认如下各内容。
1. Android DeepLink 设置 / 必备确认事项!
2. iOS DeepLink 设置 / 必备确认事项!
Android Deep Link Settings
为了在 Android 应用上设置 DeepLink 功能,请在 AndroidManifest.xml 文件里需添如下 intent-filter 内容。
<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:scheme="YOUR_SCHEME_NAME_HERE" />
</intent-filter>
还未决定 Scheme 值的情况,可以使用 adbrix 上发布的 App Key。
若 Scheme 值决定为 adbrix 123456 的话,在 AndroidManifest.xml 文件上像如下修改代码。
<activity android:label="@string/app_name" android:launchMode="singleTask" ...... >
<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:scheme="adbrix123456"/>
</intent-filter>
</activity>
注意! 为了顺利运行 DeepLink Tracking,Activity 请使用 SingleTask Mode。
DeepLink 运行测试
按照如下步骤,可以确认 DeepLink 是否正常设置。
- 上述 DeepLink 内容适用后进行打包,并安装及启动。
- 再启动 "Window 命令窗口"。( Win+R, 输入 cmd)
- 启动 adb shell。
- 输入 adb 命令语。若上述示例同样设置 Scheme 的话,在 [URL] 中输入 adbrix123456://
C:/>adb shell
[命令语句]
am start -a android.intent.action.VIEW -d [URI] [PackageName]
[示例]
am start -a android.intent.action.VIEW -d "adbrix123456://" com.myapp.packageName
参考按照上述步骤进行测试时,应用成功启动的话,这说明 DeepLink 相关内容都正常设置。
参考 Google Developer Guide,可以查看更详情的 DeepLink 内容。
DeepLink Open Tracking
通过已设置的 DeepLink 内容,用 DeepLink Tracking Link 可以开启应用。
为了提供 DeepLink Tracking Link Report,在安卓开发环境上需要注意一些例外事项。
请参考上述图表,适用解决方案。
解决方案 A. 不使用 App LaunchMode 的 SingleTask Mode,而使用其他 Mode 的话
根据不同目的,会使用 Standard, SingleTop 等 SingleTask 以外的 Mode。
若在使用像 Unity 或 Cocos2dx 的其他 Mode 的话,通过 DeepLink 打开应用时,会导致异常事项。
所以参考以下内容,在 AndroidManifest.xml 文件上添加 IgawDefaultDeeplinkActivity 的基本 DeepLink。
<activity
android:name="com.igaworks.IgawDefaultDeeplinkActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
android:noHistory="true">
<intent-filter android:label="@string/app_name">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!—请输入 DeepLink 上的 Scheme 和 Host 值。-->
<data android:scheme="YOUR_SCHEME_NAME_HERE" android:host="YOUR_HOST_NAME_HERE" />
</intent-filter>
<!—"DeepLink Tracking 后,需要向 MainActivity 处理 Redirection。因此请输入 MainActivity 的 Full Pacakge Name。" -->
<meta-data android:name="IgawRedirectActivity" android:value="INPUT_YOUR_FULL_PACKAGE_NAME_OF_MAIN_ACTIVITY"/>
</activity>
按上述内容来设置的话,通过 DeepLink 开启应用时,IgawDefaultDeeplinkActivity 被启动并进行跟踪,后开启在 IgawRedirectActivity 上设置的 DeepLink Open Activity。因此不是启动原有的 DeepLink Open Activity。.
IgawDefaultDeeplinkActivity 仅具有单纯的 Tracking 功能,所以不会对用户曝光内容。
注意! 在使用 IgawDefaultDeeplinkActivity 时,必须删除以前设置的 DeepLink 相关内容。
解决方案 B. DeepLink Open 以后再处理 Intent Data 时 (使用 SingleTask Mode 情况)
通过 DeepLink 开启应用时,使用 Intent 传达的 DeepLink Data,可以变更应用的状态。
执行相关动作后,修改或删除所有 DeepLink Data 时,无法正常运行 adbrix Tracking Link。
因此修改 DeepLink data 的 Intent 之前,需先调用 adbrix Tracking Link 的 API。
参考以下内容,请进行调用 IgawCommon.registerReferrer api。
// Example Code
public class DeeplinkActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
onNewIntent(MainActivity.this.getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
IgawCommon.registerReferrer(MainActivity.this);
}
}
iOS Deep Link Settings
为了在 iOS 应用上设置 DeepLink 功能,请在修改应用上的 info.plist 文件。
- 在 Xcode Project 中打开 Info panel。
- 在 URL types 项目上添加 URL Schemes。
- 还未决定 scheme 值的情况,可可以使用 adbrix 上发布的 App Key。
若 Scheme 值决定为 adbrix 123456 的话,像如下进行修改。
DeepLink 运行测试
按照如下步骤,可以确认 DeepLink 是否正常设置。
- 上述 DeepLink 内容适用后进行打包,并安装及启动。
- 启动设备上或模拟器的 Safari 游览器。
- 在游览器中输入 Scheme 值。按照上述示例设置 Scheme 值时,在 [URL] 中输入 adbrix123456://
成功启动应用时,说明 DeepLink 设置正常。
DeepLink Open Tracking
通过已设置的 DeepLink 内容,用 DeepLink Tracking Link 可以开启应用。
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
[IgaworksCore passOpenURL:url];
return YES;
}
#else
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
{
[IgaworksCore passOpenURL:url];
return YES;
}
#endif