处理ios18从其他app用自己键盘 拉起主app的bug
其他问题
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
#import "KBSkinManager.h"
|
||||
#import "KBAuthManager.h" // 登录态判断(共享钥匙串)
|
||||
#import "KBULBridgeNotification.h" // Darwin 通知常量(UL 已处理)
|
||||
#import "KBExtensionAppLauncher.h"
|
||||
#import "KBHostAppLauncher.h"
|
||||
#import "KBStreamTextView.h" // 流式文本视图
|
||||
#import "KBStreamOverlayView.h" // 带关闭按钮的流式层
|
||||
#import "KBFunctionTagListView.h"
|
||||
@@ -321,7 +321,7 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[ivc.extensionContext openURL:ul completionHandler:^(__unused BOOL ok) {}];
|
||||
});
|
||||
// 双路兜底:500ms 内未收到主 App 确认,则回退到自定义 Scheme
|
||||
// 双路兜底:500ms 内未收到主 App 确认,则回退到自定义 Scheme(通过宿主 UIApplication 打开)
|
||||
self.kb_ulHandledFlag = NO;
|
||||
NSUInteger token = ++self.kb_ulSeq;
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
@@ -329,14 +329,15 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/
|
||||
if (self.kb_ulHandledFlag) return; // 主 App 已确认处理
|
||||
NSURL *scheme = [NSURL URLWithString:[NSString stringWithFormat:@"%@://login?src=functionView&index=%ld&title=%@", KB_APP_SCHEME, (long)index, encodedTitle]];
|
||||
if (!scheme) return;
|
||||
[KBExtensionAppLauncher openScheme:scheme
|
||||
usingInputController:ivc
|
||||
source:self
|
||||
completion:^(BOOL success) {
|
||||
if (!success) {
|
||||
[KBHUD showInfo:KBLocalized(@"请切换到主App完成登录")];
|
||||
}
|
||||
}];
|
||||
UIResponder *start = ivc.view ?: (UIResponder *)self;
|
||||
// 让键盘失去焦点
|
||||
[ivc dismissKeyboard];
|
||||
BOOL ok = [KBHostAppLauncher openHostAppURL:scheme fromResponder:start];
|
||||
if (!ok) {
|
||||
[KBHUD showInfo:KBLocalized(@"请切换到主App完成登录")];
|
||||
}else{
|
||||
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -378,13 +379,16 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
|
||||
if (!ul) return;
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
NSURL *scheme = [NSURL URLWithString:[NSString stringWithFormat:@"%@@//login?src=functionView&index=%ld&title=%@", KB_APP_SCHEME, (long)indexPath.item, encodedTitle]];
|
||||
[KBExtensionAppLauncher openPrimaryURL:ul
|
||||
fallbackURL:scheme
|
||||
usingInputController:ivc
|
||||
source:self
|
||||
completion:^(BOOL success) {
|
||||
if (!success) {
|
||||
// 先尝试通过 extensionContext 打开 UL
|
||||
[ivc.extensionContext openURL:ul completionHandler:^(BOOL ok) {
|
||||
if (ok) {
|
||||
return;
|
||||
}
|
||||
// UL 失败时,再通过宿主 UIApplication + 自定义 Scheme 兜底
|
||||
NSURL *scheme = [NSURL URLWithString:[NSString stringWithFormat:@"%@@//login?src=functionView&index=%ld&title=%@", KB_APP_SCHEME, (long)indexPath.item, encodedTitle]];
|
||||
UIResponder *start = ivc.view ?: (UIResponder *)self;
|
||||
BOOL ok2 = [KBHostAppLauncher openHostAppURL:scheme fromResponder:start];
|
||||
if (!ok2) {
|
||||
// 两条路都失败:大概率未开完全访问或宿主拦截。统一交由 Manager 引导。
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[KBFullAccessManager shared] ensureFullAccessOrGuideInView:self];
|
||||
@@ -402,6 +406,12 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
|
||||
// - iOS16+ 会在跨 App 首次读取时自动弹出系统权限弹窗;
|
||||
// - iOS15 及以下不会弹窗,直接返回内容;
|
||||
// 注意:不要在非用户触发的时机主动读取(如 viewDidLoad),否则会造成“立刻弹窗”的体验。
|
||||
// 权限全部打开(键盘已启用 + 完全访问)。在扩展进程中仅需判断“完全访问”。
|
||||
if (![[KBFullAccessManager shared] hasFullAccess]) {
|
||||
// 未开启完全访问:保持原有引导路径
|
||||
[[KBFullAccessManager shared] ensureFullAccessOrGuideInView:self];
|
||||
return;
|
||||
}
|
||||
UIPasteboard *pb = [UIPasteboard generalPasteboard];
|
||||
NSString *text = pb.string; // 读取纯文本(可能触发系统粘贴权限弹窗)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user