在 Android 和 IOS 上,URL Scheme 是一种在应用程序之间进行通信的方式。在 Android 上,URL Scheme 通常是通过 Intent 进行处理的,而在 IOS 上,则是通过应用程序的 Info.plist 文件进行注册和处理的。
Android 上的示例代码:
1.定义 Intent:
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("myapp://example.com/page"));
2.使用 Intent 启动应用程序:
startActivity(intent);
IOS 上的示例代码:
1.在 Info.plist 中注册 URL Scheme:
CFBundleURLTypes
CFBundleURLName
CFBundleURLSchemes
myapp
2.在 AppDelegate.swift 文件中处理 URL Scheme:
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if url.scheme == "myapp" {
// 处理 URL Scheme
return true
}
return false
}