1
This commit is contained in:
@@ -238,13 +238,25 @@
|
||||
#pragma mark - Network Streaming (GET)
|
||||
|
||||
// 后端测试地址(内网)。若被 ATS 拦截,请在扩展 target 的 Info.plist 中允许 HTTP 或添加例外域。
|
||||
static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/talk";
|
||||
//static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/talk";
|
||||
|
||||
- (void)kb_startNetworkStreamingWithSeed:(NSString *)seedTitle {
|
||||
[self kb_stopNetworkStreaming];
|
||||
if (![[KBFullAccessManager shared] hasFullAccess]) { return; }
|
||||
|
||||
NSURL *url = [NSURL URLWithString:kKBStreamDemoURL];
|
||||
NSString *apiUrl = [NSString stringWithFormat:@"%@%@", KB_BASE_URL, API_AI_TALK];
|
||||
// 将选中的标签文案作为 seed 透传给后端(通过 query 参数)
|
||||
if (seedTitle.length > 0) {
|
||||
NSString *encodedSeed = [seedTitle stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]] ?: @"";
|
||||
if (encodedSeed.length > 0) {
|
||||
if ([apiUrl containsString:@"?"]) {
|
||||
apiUrl = [apiUrl stringByAppendingFormat:@"&userInput=%@", encodedSeed];
|
||||
} else {
|
||||
apiUrl = [apiUrl stringByAppendingFormat:@"?userInput=%@", encodedSeed];
|
||||
}
|
||||
}
|
||||
}
|
||||
NSURL *url = [NSURL URLWithString:apiUrl];
|
||||
if (!url) { return; }
|
||||
|
||||
self.streamHasOutput = NO; // 重置首段处理标记
|
||||
@@ -332,34 +344,42 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/
|
||||
|
||||
// 2) 权限没问题,再判断是否登录:未登录 -> 直接拉起主 App,由主 App 负责完成登录
|
||||
if (!KBAuthManager.shared.isLoggedIn) {
|
||||
|
||||
|
||||
UIInputViewController *ivc = KBFindInputViewController(self);
|
||||
if (!ivc) return;
|
||||
NSString *encodedTitle = [title stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]] ?: @"";
|
||||
NSURL *ul = [NSURL URLWithString:[NSString stringWithFormat:@"%@?src=functionView&index=%ld&title=%@", KB_UL_LOGIN, (long)index, encodedTitle]];
|
||||
if (!ul) return;
|
||||
// 发起 UL,不依赖 ok 结果
|
||||
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(通过宿主 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(), ^{
|
||||
if (token != self.kb_ulSeq) return; // 已有新请求覆盖
|
||||
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;
|
||||
UIResponder *start = ivc.view ?: (UIResponder *)self;
|
||||
// 让键盘失去焦点
|
||||
[ivc dismissKeyboard];
|
||||
BOOL ok = [KBHostAppLauncher openHostAppURL:scheme fromResponder:start];
|
||||
if (!ok) {
|
||||
[KBHUD showInfo:KBLocalized(@"请切换到主App完成登录")];
|
||||
}else{
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
NSString *schemeStr = [NSString stringWithFormat:@"%@://login?src=keyboard", KB_APP_SCHEME];
|
||||
NSURL *scheme = [NSURL URLWithString:schemeStr];
|
||||
// 从当前视图作为起点,通过响应链找到 UIApplication 再调起主 App
|
||||
BOOL ok = [KBHostAppLauncher openHostAppURL:scheme fromResponder:ivc.view];
|
||||
return;
|
||||
// if (!ivc) return;
|
||||
// NSString *encodedTitle = [title stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]] ?: @"";
|
||||
// NSURL *ul = [NSURL URLWithString:[NSString stringWithFormat:@"%@?src=functionView&index=%ld&title=%@", KB_UL_LOGIN, (long)index, encodedTitle]];
|
||||
// if (!ul) return;
|
||||
// // 发起 UL,不依赖 ok 结果
|
||||
// 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(通过宿主 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(), ^{
|
||||
// if (token != self.kb_ulSeq) return; // 已有新请求覆盖
|
||||
// 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;
|
||||
// UIResponder *start = ivc.view ?: (UIResponder *)self;
|
||||
// // 让键盘失去焦点
|
||||
// [ivc dismissKeyboard];
|
||||
// BOOL ok = [KBHostAppLauncher openHostAppURL:scheme fromResponder:start];
|
||||
// if (!ok) {
|
||||
// [KBHUD showInfo:KBLocalized(@"请切换到主App完成登录")];
|
||||
// }else{
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// return;
|
||||
}
|
||||
|
||||
// 3) 已登录:开始业务逻辑(展示加载并拉取流式内容)
|
||||
|
||||
Reference in New Issue
Block a user