获取extension,判断第一次
This commit is contained in:
@@ -9,12 +9,13 @@
|
|||||||
|
|
||||||
@implementation KBToolBar
|
@implementation KBToolBar
|
||||||
|
|
||||||
/*
|
- (instancetype)initWithFrame:(CGRect)frame{
|
||||||
// Only override drawRect: if you perform custom drawing.
|
if (self = [super initWithFrame:frame]) {
|
||||||
// An empty implementation adversely affects performance during animation.
|
|
||||||
- (void)drawRect:(CGRect)rect {
|
|
||||||
// Drawing code
|
|
||||||
}
|
}
|
||||||
*/
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -38,15 +38,53 @@ static BOOL KBIsKeyboardEnabled(void) {
|
|||||||
ViewController *vc = [[ViewController alloc] init];
|
ViewController *vc = [[ViewController alloc] init];
|
||||||
self.window.rootViewController = vc;
|
self.window.rootViewController = vc;
|
||||||
|
|
||||||
// Present guide if the custom keyboard is not enabled yet
|
// [[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
// selector:@selector(applicationDidBecomeActiveNotification:)
|
||||||
|
// name:UIApplicationDidBecomeActiveNotification
|
||||||
|
// object:nil];
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
if (!KBIsKeyboardEnabled()) {
|
[self kb_presentPermissionIfNeeded];
|
||||||
KBPermissionViewController *guide = [KBPermissionViewController new];
|
|
||||||
guide.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
||||||
[self.window.rootViewController presentViewController:guide animated:YES completion:nil];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
//#pragma mark - Active notifications
|
||||||
|
//
|
||||||
|
//- (void)applicationDidBecomeActiveNotification:(NSNotification *)note
|
||||||
|
//{
|
||||||
|
// [self kb_presentPermissionIfNeeded];
|
||||||
|
//}
|
||||||
|
|
||||||
|
#pragma mark - Permission presentation
|
||||||
|
|
||||||
|
- (UIViewController *)kb_topMostViewController
|
||||||
|
{
|
||||||
|
UIViewController *root = self.window.rootViewController;
|
||||||
|
if (!root) return nil;
|
||||||
|
UIViewController *top = root;
|
||||||
|
while (top.presentedViewController) {
|
||||||
|
top = top.presentedViewController;
|
||||||
|
}
|
||||||
|
return top;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)kb_presentPermissionIfNeeded
|
||||||
|
{
|
||||||
|
BOOL enabled = KBIsKeyboardEnabled();
|
||||||
|
UIViewController *top = [self kb_topMostViewController];
|
||||||
|
if (!top) return;
|
||||||
|
if ([top isKindOfClass:[KBPermissionViewController class]]) {
|
||||||
|
if (enabled) {
|
||||||
|
[top dismissViewControllerAnimated:YES completion:nil];
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!enabled) {
|
||||||
|
KBPermissionViewController *guide = [KBPermissionViewController new];
|
||||||
|
guide.modalPresentationStyle = UIModalPresentationFullScreen;
|
||||||
|
[top presentViewController:guide animated:YES completion:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict/>
|
<dict>
|
||||||
|
<key>NSAppTransportSecurity</key>
|
||||||
|
<dict>
|
||||||
|
<key>NSAllowsArbitraryLoads</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
18
keyBoard/Settings.bundle/Root.plist
Normal file
18
keyBoard/Settings.bundle/Root.plist
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>PreferenceSpecifiers</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>Title</key>
|
||||||
|
<string>Keyboard</string>
|
||||||
|
<key>Type</key>
|
||||||
|
<string>PSGroupSpecifier</string>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
<key>StringsTable</key>
|
||||||
|
<string>Root</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
|
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
self.view.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
|
self.view.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
|
||||||
|
|
||||||
// Close button (top-right)
|
|
||||||
UIButton *close = [UIButton buttonWithType:UIButtonTypeSystem];
|
UIButton *close = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||||
[close setTitle:@"X" forState:UIControlStateNormal];
|
[close setTitle:@"X" forState:UIControlStateNormal];
|
||||||
close.titleLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightSemibold];
|
close.titleLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightSemibold];
|
||||||
@@ -28,7 +27,6 @@
|
|||||||
[close addTarget:self action:@selector(dismissSelf) forControlEvents:UIControlEventTouchUpInside];
|
[close addTarget:self action:@selector(dismissSelf) forControlEvents:UIControlEventTouchUpInside];
|
||||||
[self.view addSubview:close];
|
[self.view addSubview:close];
|
||||||
|
|
||||||
// Title
|
|
||||||
UILabel *title = [[UILabel alloc] init];
|
UILabel *title = [[UILabel alloc] init];
|
||||||
title.text = @"启用输入法";
|
title.text = @"启用输入法";
|
||||||
title.font = [UIFont systemFontOfSize:22 weight:UIFontWeightSemibold];
|
title.font = [UIFont systemFontOfSize:22 weight:UIFontWeightSemibold];
|
||||||
@@ -38,7 +36,6 @@
|
|||||||
title.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
title.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
||||||
[self.view addSubview:title];
|
[self.view addSubview:title];
|
||||||
|
|
||||||
// Step tips
|
|
||||||
UILabel *tips = [[UILabel alloc] init];
|
UILabel *tips = [[UILabel alloc] init];
|
||||||
tips.text = @"1 开启键盘 > 2 允许完全访问";
|
tips.text = @"1 开启键盘 > 2 允许完全访问";
|
||||||
tips.font = [UIFont systemFontOfSize:14];
|
tips.font = [UIFont systemFontOfSize:14];
|
||||||
@@ -48,7 +45,6 @@
|
|||||||
tips.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
tips.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
||||||
[self.view addSubview:tips];
|
[self.view addSubview:tips];
|
||||||
|
|
||||||
// Illustration placeholder (simple rounded rect)
|
|
||||||
UIView *card = [[UIView alloc] initWithFrame:CGRectMake(32, CGRectGetMaxY(tips.frame) + 28, self.view.bounds.size.width - 64, 260)];
|
UIView *card = [[UIView alloc] initWithFrame:CGRectMake(32, CGRectGetMaxY(tips.frame) + 28, self.view.bounds.size.width - 64, 260)];
|
||||||
card.backgroundColor = [UIColor whiteColor];
|
card.backgroundColor = [UIColor whiteColor];
|
||||||
card.layer.cornerRadius = 16;
|
card.layer.cornerRadius = 16;
|
||||||
@@ -57,7 +53,6 @@
|
|||||||
card.layer.shadowRadius = 12;
|
card.layer.shadowRadius = 12;
|
||||||
[self.view addSubview:card];
|
[self.view addSubview:card];
|
||||||
|
|
||||||
// Button to open Settings
|
|
||||||
UIButton *open = [UIButton buttonWithType:UIButtonTypeSystem];
|
UIButton *open = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||||
[open setTitle:@"去设置中开启" forState:UIControlStateNormal];
|
[open setTitle:@"去设置中开启" forState:UIControlStateNormal];
|
||||||
open.titleLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
|
open.titleLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
|
||||||
@@ -70,7 +65,6 @@
|
|||||||
[open addTarget:self action:@selector(openSettings) forControlEvents:UIControlEventTouchUpInside];
|
[open addTarget:self action:@selector(openSettings) forControlEvents:UIControlEventTouchUpInside];
|
||||||
[self.view addSubview:open];
|
[self.view addSubview:open];
|
||||||
|
|
||||||
// Bottom helper text
|
|
||||||
UILabel *help = [[UILabel alloc] init];
|
UILabel *help = [[UILabel alloc] init];
|
||||||
help.text = @"没有找到键盘? 请前往 设置 > 通用 > 键盘 > 键盘 > 添加新键盘";
|
help.text = @"没有找到键盘? 请前往 设置 > 通用 > 键盘 > 键盘 > 添加新键盘";
|
||||||
help.font = [UIFont systemFontOfSize:12];
|
help.font = [UIFont systemFontOfSize:12];
|
||||||
@@ -87,20 +81,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)openSettings {
|
- (void)openSettings {
|
||||||
// In app extensions you cannot call UIApplication. Use extension-safe code.
|
|
||||||
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
||||||
|
|
||||||
//#if TARGET_OS_APP_EXTENSION
|
|
||||||
// // Try to open Settings via the extension context (extension-safe). This may
|
|
||||||
// // fail depending on the extension type and system policy.
|
|
||||||
// if (self.extensionContext) {
|
|
||||||
// if (@available(iOS 10.0, *)) {
|
|
||||||
// [self.extensionContext openURL:url completionHandler:nil];
|
|
||||||
// } else {
|
|
||||||
// [self.extensionContext openURL:url completionHandler:nil];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//#else
|
|
||||||
UIApplication *app = [UIApplication sharedApplication];
|
UIApplication *app = [UIApplication sharedApplication];
|
||||||
if ([app canOpenURL:url]) {
|
if ([app canOpenURL:url]) {
|
||||||
if (@available(iOS 10.0, *)) {
|
if (@available(iOS 10.0, *)) {
|
||||||
@@ -109,7 +90,6 @@
|
|||||||
[app openURL:url];
|
[app openURL:url];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -8,22 +8,29 @@
|
|||||||
#import "ViewController.h"
|
#import "ViewController.h"
|
||||||
|
|
||||||
@interface ViewController ()
|
@interface ViewController ()
|
||||||
@property (nonatomic,strong)UITextField *textField;
|
@property (nonatomic, strong) UITextView *textView;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation ViewController
|
@implementation ViewController
|
||||||
|
|
||||||
- (void)viewDidLoad {
|
- (void)viewDidLoad {
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
// Do any additional setup after loading the view.
|
[self setupTextField];
|
||||||
self.view.backgroundColor = [UIColor grayColor];
|
}
|
||||||
self.textField = [[UITextField alloc] init];
|
|
||||||
self.textField.frame = CGRectMake(100, 100, 200, 40);
|
|
||||||
self.textField.layer.borderWidth = 1;
|
|
||||||
self.textField.layer.borderColor = [UIColor redColor].CGColor;
|
|
||||||
[self.view addSubview:self.textField];
|
|
||||||
|
|
||||||
|
- (void)setupTextField {
|
||||||
|
CGRect frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 200)/2, ([UIScreen mainScreen].bounds.size.height - 200)/2, 200, 200);
|
||||||
|
self.textView = [[UITextView alloc] initWithFrame:frame];
|
||||||
|
self.textView.text = @"测试";
|
||||||
|
self.textView.layer.borderColor = [UIColor blackColor].CGColor;
|
||||||
|
self.textView.layer.borderWidth = 0.5;
|
||||||
|
[self.view addSubview:self.textView];
|
||||||
|
|
||||||
|
[self.textView becomeFirstResponder];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||||||
|
[self.textView resignFirstResponder];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user