1
This commit is contained in:
@@ -100,6 +100,8 @@ static NSString *KBFormatMB(uint64_t bytes) {
|
||||
[self kb_consumePendingShopSkin];
|
||||
[self kb_applyDefaultSkinIfNeeded];
|
||||
|
||||
[self kb_startObservingAppGroupChanges];
|
||||
|
||||
// 监听 App Group 配置变化,动态切换键盘布局
|
||||
[self kb_checkAndApplyLayoutIfNeeded];
|
||||
}
|
||||
@@ -236,6 +238,7 @@ static NSString *KBFormatMB(uint64_t bytes) {
|
||||
removeObserver:self.kb_skinObserverToken];
|
||||
self.kb_skinObserverToken = nil;
|
||||
}
|
||||
[self kb_stopObservingAppGroupChanges];
|
||||
[self kb_unregisterDarwinSkinInstallObserver];
|
||||
#if DEBUG
|
||||
if (_kb_debugDidCountAlive) {
|
||||
@@ -275,10 +278,34 @@ static NSString *KBFormatMB(uint64_t bytes) {
|
||||
}
|
||||
|
||||
- (void)kb_updateSuggestionEngineType:(NSString *)engineType {
|
||||
// 根据 engineType 切换不同的联想引擎
|
||||
// 例如:latin, pinyin_traditional, pinyin_simplified, bopomofo
|
||||
NSLog(@"[KeyboardViewController] Switching suggestion engine to: %@", engineType);
|
||||
[[KBSuggestionEngine shared] setEngineTypeFromString:engineType];
|
||||
}
|
||||
|
||||
#pragma mark - App Group KVO
|
||||
|
||||
- (void)kb_startObservingAppGroupChanges {
|
||||
NSUserDefaults *appGroup = [[NSUserDefaults alloc] initWithSuiteName:AppGroup];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
self.kb_appGroupObserverToken = [[NSNotificationCenter defaultCenter]
|
||||
addObserverForName:NSUserDefaultsDidChangeNotification
|
||||
object:appGroup
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(__unused NSNotification *_Nonnull note) {
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
if (!strongSelf) { return; }
|
||||
[strongSelf kb_checkAndApplyLayoutIfNeeded];
|
||||
}];
|
||||
|
||||
NSLog(@"[KeyboardViewController] Started observing App Group changes");
|
||||
}
|
||||
|
||||
- (void)kb_stopObservingAppGroupChanges {
|
||||
if (self.kb_appGroupObserverToken) {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self.kb_appGroupObserverToken];
|
||||
self.kb_appGroupObserverToken = nil;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user