简体   繁体   English

当用户点击应用中的任何链接时,如何阻止我的ios应用打开网址?

[英]How do i stop my ios app from opening a url when user taps on any link in the app?

当我使用从api获取的数据填充它时,我想阻止我的应用打开可能出现在textview中的URL。

Unchecked " Link " and " Address " flag to disable URLs which exist in UItextview , see the following. 取消选中“ Link ”和“ Address ”标记以禁用UItextview中存在的UItextview ,请参阅以下内容。

在此处输入图片说明

您可以使用以下代码:

textView.dataDetectorTypes = []

If you implement textView(_:shouldInteractWith:in:interaction:) of the UITextViewDelegate you can control whether the URL should be opened or not. 如果实现UITextViewDelegate的 textView(_:shouldInteractWith:in:interaction :) ,则可以控制是否应打开URL。

Just return false if you don't want any URL to be handled: 如果您不希望处理任何URL,只需返回false

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
    return false
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当用户点击iOS中另一个应用程序上的链接时,如何启动我的应用程序? - How can I launch my app when a user taps on a link on another app in iOS? 在Safari中打开链接时如何将用户重定向到应用程序? - How do I redirect a User to the app when opening a link in Safari? 当用户点击我的应用程序中的字段时如何弹出应用程序 - How to pop up an app when user taps a field in my app 如何使用用户名链接到iOS App中的Facebook用户? - How do I link to a Facebook user in the iOS App by using the username? 如何使用Swift从WebKit iOS应用中的tel:url链接打开电话 - How do I open phone from tel: url link from WebKit iOS app using Swift 如何将我的ios应用链接和同步到cloudantnosqlite? - How do i link and sync my ios app to cloudantnosqlite? 在我的 iOS 应用中包含 HTTP(非 HTTPS)URL 链接,我是否需要禁用应用传输安全? - Included a HTTP (not HTTPS) URL link in my iOS App, do I need to disable App Transport Security? 当用户在iOS中删除我的应用时,我可以做什么? - Can I do something when user deletes my app in iOS? 如何使用自定义iOS应用程序中的URL链接将Safari(或Adobe或任何其他应用程序)打开到特定网页或文档? - How to open Safari (or Adobe, or any other app) to a specific webpage or document using a URL link from within my custom iOS application? 当我的ios应用程序连接到互联网时,如何在不重新打开该应用程序的情况下刷新我的ios应用程序 - How can i refresh my ios app when my ios app get connected to the internet without re-opening the app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM