获取extension,判断第一次

This commit is contained in:
2025-10-27 21:11:28 +08:00
parent a9625369f7
commit d4ebfb9909
6 changed files with 92 additions and 42 deletions

View File

@@ -18,7 +18,6 @@
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
// Close button (top-right)
UIButton *close = [UIButton buttonWithType:UIButtonTypeSystem];
[close setTitle:@"X" forState:UIControlStateNormal];
close.titleLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightSemibold];
@@ -28,7 +27,6 @@
[close addTarget:self action:@selector(dismissSelf) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:close];
// Title
UILabel *title = [[UILabel alloc] init];
title.text = @"启用输入法";
title.font = [UIFont systemFontOfSize:22 weight:UIFontWeightSemibold];
@@ -38,7 +36,6 @@
title.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:title];
// Step tips
UILabel *tips = [[UILabel alloc] init];
tips.text = @"1 开启键盘 > 2 允许完全访问";
tips.font = [UIFont systemFontOfSize:14];
@@ -48,7 +45,6 @@
tips.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[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)];
card.backgroundColor = [UIColor whiteColor];
card.layer.cornerRadius = 16;
@@ -57,7 +53,6 @@
card.layer.shadowRadius = 12;
[self.view addSubview:card];
// Button to open Settings
UIButton *open = [UIButton buttonWithType:UIButtonTypeSystem];
[open setTitle:@"去设置中开启" forState:UIControlStateNormal];
open.titleLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
@@ -70,7 +65,6 @@
[open addTarget:self action:@selector(openSettings) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:open];
// Bottom helper text
UILabel *help = [[UILabel alloc] init];
help.text = @"没有找到键盘? 请前往 设置 > 通用 > 键盘 > 键盘 > 添加新键盘";
help.font = [UIFont systemFontOfSize:12];
@@ -87,20 +81,7 @@
}
- (void)openSettings {
// In app extensions you cannot call UIApplication. Use extension-safe code.
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];
if ([app canOpenURL:url]) {
if (@available(iOS 10.0, *)) {
@@ -109,7 +90,6 @@
[app openURL:url];
}
}
//#endif
}
@end