[英]iOS 8.3, Keyboard Extenstion Safari issue
I'm making the iOS keyboard extension. 我正在做iOS键盘扩展。
But When I do following code after button click in Safari Web, the proxy( UITextDocumentProxy
) stopped. 但是当我在Safari Web中单击按钮后执行以下代码时,代理(
UITextDocumentProxy
)停止了。
[self.textDocumentProxy adjustTextPositionByCharacterOffset:-5];//stop here
for (int i = 0; i < 10; i ++) {
[self.textDocumentProxy deleteBackward];
}
[self.textDocumentProxy insertText:@"__________"];
It works well in safari-top-search-bar, but stop at other plain textbox. 它在safari-top-search-bar中效果很好,但在其他普通文本框中停止。
dispatch_queue_t myQueue = dispatch_queue_create("com.test.online",0);
dispatch_async(myQueue, ^{
[self.textDocumentProxy adjustTextPositionByCharacterOffset:-5];
[NSThread sleepForTimeInterval:0.1];
for (int i = 0; i < 10; i ++) {
[self.textDocumentProxy deleteBackward];
}
[self.textDocumentProxy insertText:@"__________"];
});
If I put the block into dispatch_async on another queue with some delay after adjustTextPositionByCharacterOffset . 如果我在AdjustTextPositionByCharacterOffset之后将块放入另一个队列中的dispatch_async中,但有一些延迟。 It_works
有用
However it makes my code slow in whole other apps also. 但是,这也会使我的代码在其他所有应用程序中的运行速度变慢。
Any good idea? 有什么好主意吗? or Is there any way to detect whether it is Safari or Not?
或有什么方法可以检测它是否是Safari?
I've experienced the same problem. 我遇到了同样的问题。 It seems that if you do
insertText
or adjustTextPosition
, you can't immediately call deleteBackward
or adjustTextPosition
. 看来,如果您执行
insertText
或adjustTextPosition
,则无法立即调用deleteBackward
或adjustTextPosition
。 Our current workaround is to use NSTimer to delay for some time: 我们当前的解决方法是使用NSTimer延迟一段时间:
[self.textDocumentProxy adjustTextPositionByCharacterOffset:-5];
[self delayedDelete];
While delayedDelete
could be like: 而
delayedDelete
可能像:
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(deleteBackward) userInfo:nil repeats:NO];
I'm thinking it's a bug of iOS and not documented yet. 我认为这是iOS的错误,尚未记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.