iOS第三方键盘

作者: 幂琪有天 | 来源:发表于2016-03-11 13:12 被阅读584次

如果需要开发第三方键盘 首先得了解一下苹果官方文档 https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html
然后建议看一下 APPExtension
http://www.cocoachina.com/ios/20140918/9677.html

键盘应用属于你的hostAPP 所以你要了解appGroups来做到两个应用间信息传输

使用方法

NSUserDefaults *keyboarddefaults = [[NSUserDefaults alloc] initWithSuiteName:appGroups];

appGroups是我们设置的字段 与添加appGroup的字段一致

xcode会给我们生成keyboard的类 在这个类 我们可以做第三方键盘

1.这个类中建议用autolayout做约束

CGFloat _expandedHeight = 256;
NSLayoutConstraint *_heightConstraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute   multiplier:0 constant: _expandedHeight];
[self.view addConstraint: _heightConstraint];  

该方法可以设置键盘高度
我遇到的问题:在updateContraint 中调用无效

3.输入文字:调用协议方法 textDocumentProxy.

   - (BOOL)hasText;

   - (void)insertText:(NSString *)text; //输入文字

   - (void)deleteBackward;//删除文字

我们的键盘如果要通过审核 就必须要有一个下一个输入法的按钮 参照原生的那个地球按钮

- (void)advanceToNextInputMode 

这个方法就可以完成

apple开放的API较少 自己看文档是个很好的选择

4 还遇到一个问题:暂时无法做到从自己的键盘端跳转到mainApp

 以前使用webview是可以做到 但是apple更新之后禁用这个方法  stackOverflow上的建议也无效 

 希望有解决这个问题的人可以告诉我

https://github.com/huangWay?tab=repositories

相关文章

网友评论

  • 636ccfc89aac:感谢楼主的分享.想请教一下 我要如何判断自己开发的第三方输入法,用户使用时在系统里开启了呢(单纯的启用,不包括完全访问)
    幂琪有天:@妹Show 这个我还真不知道
  • 636ccfc89aac:键盘跳转mainApp方法如下:
    mainApp字段是提前设置好的URL Types
    UIResponder *responder = self;

    while (responder) {

    if ([responder isKindOfClass:[UIApplication class]]) {

    NSLog(@"yes:%@", responder);

    break;

    }

    responder = [responder nextResponder];

    NSLog(@"responder:%@", responder);

    }

    NSString* toUtf8= [@"mainApp://" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];



    NSURL* url = [NSURL URLWithString:toUtf8];



    [responder performSelector:@selector(openURL:) withObject:url];

    // [(UIApplication *)responder canOpenURL:url];

    NSLog(@"--------%@",url);

    [[self extensionContext] openURL:url completionHandler:^(BOOL success) {

    NSLog(@"Success? %i", success);

    }];
  • ce70df11c8e3:哥哥:我在真机上跑你的代码,崩溃了。iOS 10.3.2
    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController clear:]: unrecognized selector sent to instance 0x10020c010'
    幂琪有天:@撸撸更健康 我记得我这个没有没有在github上传过代码啊,可以发一下你下载的链接不
    ce70df11c8e3:@幂琪有天 不是啊,我刚到git上下了楼主的代码,在我的机上跑,点击了“清除”按钮,就崩了
    幂琪有天:@撸撸更健康 viewController 找不到clear方法,这个方法是你自己定义的吗

本文标题:iOS第三方键盘

本文链接:https://www.haomeiwen.com/subject/utxxlttx.html