CoD*_*oDe 13 android deep-linking ios firebase firebase-dynamic-links
我正在集成Firebase以支持应用中的Deeplink功能.我在屏幕示例建议(PFA)中看到,我们可以添加自己的自定义文本,而不是显示深层链接网址.
我试图更新,但没有帮助.怎么做,有什么建议吗?
我的猜测是,UITextView当用户输入文本时(在 iOS 中),您正在使用 for 。以下是如何在 Swift 中实现这一点:
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func buttonPress(_ sender: Any) {
let range = textView.selectedRange
let linkString = NSMutableAttributedString(string: textView.text)
linkString.addAttribute(NSLinkAttributeName, value: textField.text ?? "", range: range)
textView.attributedText = linkString
}
}
extension ViewController: UITextViewDelegate {
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
UIApplication.shared.open(URL, options: [:], completionHandler: nil)
return false
}
}
Run Code Online (Sandbox Code Playgroud)
在 Android 中,我发现了几个似乎很好地处理这个主题的答案:
来自用户370305:
试试这个,让我知道会发生什么..
Run Code Online (Sandbox Code Playgroud)TextView textView =(TextView)findViewById(R.id.textView); textView.setClickable(true); textView.setMovementMethod(LinkMovementMethod.getInstance()); String text = "<a href='http://www.google.com'> Google </a>"; textView.setText(Html.fromHtml(text));
来自罗宾汉:
将您的 html 放入 string@ 中
Run Code Online (Sandbox Code Playgroud)<string url="link"><a href="http://www.google.com">Google</a></string>将字符串设置为 editText@
Run Code Online (Sandbox Code Playgroud)youredittext.setText(Html.fromHtml(getResources().getString(R.string.url)));对于点击,请设置 LinkMovementMethod 和必要的 action@
Run Code Online (Sandbox Code Playgroud)youredittext.setMovementMethod(LinkMovementMethod.getInstance());
如果您尝试在 HTML 中完成此操作,请使用锚 ( a) 标记:
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func buttonPress(_ sender: Any) {
let range = textView.selectedRange
let linkString = NSMutableAttributedString(string: textView.text)
linkString.addAttribute(NSLinkAttributeName, value: textField.text ?? "", range: range)
textView.attributedText = linkString
}
}
extension ViewController: UITextViewDelegate {
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
UIApplication.shared.open(URL, options: [:], completionHandler: nil)
return false
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1244 次 |
| 最近记录: |