我正在使用UITextView
委托方法来执行一些自定义工作,例如当用户点击URL或附件时打开应用内浏览器:
func textView(_ textView: UITextView,
shouldInteractWith URL: URL,
in characterRange: NSRange,
interaction: UITextItemInteraction) -> Bool
在iOS 13中,即使用户只是在URL上滚动(这是不期望的),也会调用此委托方法。此行为也适用于图像附件。
现在通过交互调用该dele方法。
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 6.1 7.1
* frame #0: 0x0000000104a54c5c ProjectS1`PostListViewController.textView(textView=0x00000001090a4600, URL=Foundation.URL @ 0x000000016b5d1200, characterRange=location=161, length=9, interaction=invokeDefaultAction, self=0x0000000109b03990) at PostListViewController.swift:610:9
frame #1: 0x0000000104a54d70 ProjectS1`@objc PostListViewController.textView(_:shouldInteractWith:in:interaction:) at <compiler-generated>:0
frame #2: 0x00000001b3293eec UIKitCore`-[UITextView _allowInteraction:forTextInteractableItem:] + 212
frame #3: 0x00000001b2602160 UIKitCore`-[_UITextInteractableItem _allowInteraction:] + 140
frame #4: 0x00000001b2601f68 UIKitCore`-[_UITextInteractableItem canInvokeDefaultAction] + 100
frame #5: 0x00000001b31dd528 UIKitCore`-[_UITextSimpleLinkInteraction _canBeginInteractionSessionForLinkAtPoint:asTap:] + 136
frame #6: 0x00000001b31dd3d0 UIKitCore`-[_UITextSimpleLinkInteraction interaction_gestureRecognizer:shouldReceiveTouch:] + 228
frame #7: 0x00000001b31dc234 UIKitCore`-[UITextInteraction gestureRecognizer:shouldReceiveTouch:] + 144
frame #8: 0x00000001b2b5f460 UIKitCore`-[UIGestureRecognizer _delegateShouldReceiveTouch:] + 452
frame #9: 0x00000001b2b5edf4 UIKitCore`-[UIGestureRecognizer _shouldReceiveTouch:forEvent:recognizerView:] + 488
frame #10: 0x00000001b2ffa630 UIKitCore`__56-[UITouchesEvent _addGestureRecognizersForView:toTouch:]_block_invoke + 332
frame #11: 0x00000001b2ffa0e4 UIKitCore`__62-[UITouchesEvent _collectGestureRecognizersForView:withBlock:]_block_invoke + 408
frame #12: 0x00000001b2ff9b58 UIKitCore`-[UITouchesEvent _collectGestureRecognizersForView:withBlock:] + 308
frame #13: 0x00000001b2ffa4b0 UIKitCore`-[UITouchesEvent _addGestureRecognizersForView:toTouch:] + 164
frame #14: 0x00000001b2ffa9a8 UIKitCore`-[UITouchesEvent _addTouch:forDelayedDelivery:] + 812
frame #15: 0x00000001b300bfac UIKitCore`_AddTouchToEventAndDetermineIfNeedsCancel + 196
frame #16: 0x00000001b300c074 UIKitCore`____updateTouchesWithDigitizerEventAndDetermineIfShouldSend_block_invoke.96 + 136
frame #17: 0x00000001aef35b20 CoreFoundation`__NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ + 24
frame #18: 0x00000001aef360e4 CoreFoundation`____NSDictionaryEnumerate_block_invoke.11 + 56
frame #19: 0x00000001aef07a10 CoreFoundation`CFBasicHashApply + 144
frame #20: 0x00000001aef35c80 CoreFoundation`__NSDictionaryEnumerate + 220
frame #21: 0x00000001b300d560 UIKitCore`__dispatchPreprocessedEventFromEventQueue + 2444
frame #22: 0x00000001b30107dc UIKitCore`__handleEventQueueInternal + 4928
frame #23: 0x00000001b3009960 UIKitCore`__handleHIDEventFetcherDrain + 112
frame #24: 0x00000001aee61260 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
frame #25: 0x00000001aee611b4 CoreFoundation`__CFRunLoopDoSource0 + 84
frame #26: 0x00000001aee60920 CoreFoundation`__CFRunLoopDoSources0 + 184
frame #27: 0x00000001aee5b7ec CoreFoundation`__CFRunLoopRun + 1068
frame #28: 0x00000001aee5b098 CoreFoundation`CFRunLoopRunSpecific + 480
frame #29: 0x00000001b8fc5534 GraphicsServices`GSEventRunModal + 108
frame #30: 0x00000001b2f7b7ac UIKitCore`UIApplicationMain + 1940
frame #31: 0x0000000104b090d0 ProjectS1`main at AppDelegate.swift:25:7
frame #32: 0x00000001aecdaf30 libdyld.dylib`start + 4
所以我的问题是,有什么办法可以知道用户是点击URL还是滚动URL?
1
这是iOS 13.1中的“已知”问题。众所周知,开发人员一直在发布推文,我们中的许多人都提交了错误报告。从iOS 13.2 beta种子1开始,它仍未修复。提交错误并选择解决方法-由您决定,并取决于应用程序的工作方式-您什么都不做,可以等待,也可以尝试解决方法(例如,此线程中描述的一种方法-twitter.com/scelis/status/ 1176676097754198017)。我个人所做的事情在某些地方什么都没有,在其他地方,我删除了UITextViewDelegate并让默认行为接管了(在Safari中打开链接)。
—
bpapa