我想在我的自定义键盘扩展应用程序中检测哪个应用程序正在使用我的扩展。我们可以在键盘扩展中检测有关应用程序正在使用我的扩展的任何信息。我不认为这是可能的。如果任何机构有关于这方面的知识请分享它。谢谢
vdzxcuhz1#
您可以在UIInputViewController中尝试此代码
override public func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) if let parentViewController = self.parentViewController { var hostBundleID = parentViewController.valueForKey("_hostBundleID") println(hostBundleID) } }
但我不确定苹果会批准你发布到应用程序商店
3wabscal2#
ios 16+,“_主机绑定ID”的值为空
hm2xizp93#
适用于iOS 16+
#import <dlfcn.h> + (nullable NSString *)hostBundleIDWithInputVC:(UIInputViewController *)vc { NSString *bundleID = nil; @try { bundleID = [vc.parentViewController valueForKey:@"_hostBundleID"]; } @catch (NSException *exception) { NSLog(@"hostBundleID Get Failure 1 %@", exception); } @finally { } if(XMUtils.validString(bundleID) && ![bundleID isEqual:@"<null>"]) { return bundleID; } // 云控禁止xpc取法 // xpc取法 逆向自xx输入法 主要解决iOS16上获取不到的问题 @try { id hostPid = [vc.parentViewController valueForKey:@"_hostPID"]; if (hostPid) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" id serverIns = [NSClassFromString(@"PKService") performSelector:NSSelectorFromString(@"defaultService")]; id lities = [serverIns performSelector:NSSelectorFromString(@"personalities")]; id infos = [lities objectForKey:[NSBundle mainBundle].bundleIdentifier]; id info = [infos objectForKey:hostPid]; id con = [info performSelector:NSSelectorFromString(@"connection")]; id xpcCon = [con performSelector:NSSelectorFromString(@"_xpcConnection")]; #pragma clang diagnostic pop const char * (* cfunc)(id) = dlsym(RTLD_DEFAULT, "xpc_connection_copy_bundle_id"); if (cfunc != nil && xpcCon != nil) { const char *res = cfunc(xpcCon); bundleID = [NSString stringWithUTF8String:res]; return bundleID; } } } @catch (NSException *exception) { NSLog(@"hostBundleID Get Failure 2 %@", exception); } @finally { } return nil; }
from blog
3条答案
按热度按时间vdzxcuhz1#
您可以在UIInputViewController中尝试此代码
但我不确定苹果会批准你发布到应用程序商店
3wabscal2#
ios 16+,“_主机绑定ID”的值为空
hm2xizp93#
适用于iOS 16+
from blog