[英]iOS AlertView App Extension
I'm working in a custom keyboard
(iOS App Extension)
. 我正在使用自定义
keyboard
(iOS App Extension)
。 I have a UICollectionView
in my Keyboard
Layout
, so when one item
is selected I want to show a message
( UIAlerView
for example). 我有一个
UICollectionView
在我的Keyboard
Layout
,所以当一个item
选择我要显示一个message
( UIAlerView
为例)。
Here is my code: 这是我的代码:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
...
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"My Title"
message:@"Enter User Credentials"
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
}
I get this error: 'Feature not available in extensions of type com.apple.keyboard-service'
我收到此错误:
'Feature not available in extensions of type com.apple.keyboard-service'
So...is there any way to show a message
from an App Extension
? 那么...有没有办法显示来自
App Extension
的message
?
EDIT: 编辑:
Here is an example. 这是一个例子。 The
IKEA Emoticons Keyboard
shows a message (like an Android Toast
after selecting one item). IKEA Emoticons Keyboard
显示一条消息(选择一项后就像Android Toast
)。
I also have tried this library: 我也尝试过这个库:
Sad to say that, but there's no way to show a UIAlertView in keyboard extension. 说来可悲的是,但没有办法来显示键盘扩展UIAlertView中。 Actually, nothing above the frame of InputViewController can be showed.
实际上,在InputViewController框架上方无法显示任何内容。 It's pretty clear in the Apple's doc:
在苹果的文档中很明显:
...a custom keyboard can draw only within the primary view of its UIInputViewController object... it is not possible to display key artwork above the top edge of a custom keyboard's primary view, as the system keyboard does on iPhone when you tap and hold a key in the top row.
...自定义键盘只能在其UIInputViewController对象的主视图内进行绘制...无法在自定义键盘的主视图的顶部边缘上方显示按键图稿,就像在您点击和时系统键盘在iPhone上一样在第一行中按住一个键。
As for message inside the keyboard, there are some useful libraries that can help us with it. 至于键盘内的消息,有一些有用的库可以帮助我们。 For example https://github.com/scalessec/Toast and https://github.com/sergeylenkov/PTHintController .
例如https://github.com/scalessec/Toast和https://github.com/sergeylenkov/PTHintController 。
Finally I solved the problem. 最后我解决了这个问题。 It's not the best solution, but at least I get the effect that I wanted.
这不是最佳解决方案,但至少我得到了想要的效果。
I've created a View
simulating a Toast
in the xib
file and set it to hidden
. 我创建了一个
View
模拟Toast
在xib
文件,并将其设置为hidden
。
When the item is selected, I show the "faked" Toast
for 2 seconds and hide it again. 选中该项目后,我将显示“伪造”
Toast
2秒钟,然后再次将其隐藏。
self.popUpView.hidden = NO;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2.0 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
self.popUpView.hidden = YES;
});
I don't know if it's a good solution, but I really had to find a solution for that. 我不知道这是否是一个好的解决方案,但我确实必须为此找到解决方案。
For Swift you can use this : 对于Swift,您可以使用:
self.popUpView.isHidden = false
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
self.popUpView.isHidden = true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.