iOS AlertView App Extension

假如想象 提交于 2019-12-06 21:46:32

Sad to say that, but there's no way to show a UIAlertView in keyboard extension. Actually, nothing above the frame of InputViewController can be showed. 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.

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.

Ale

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.

When the item is selected, I show the "faked" Toast for 2 seconds and hide it again.

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 :

self.popUpView.isHidden = false
    DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
        self.popUpView.isHidden = true
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!