简体   繁体   English

从键盘扩展名检测源可执行文件

[英]Detect source executable from keyboard extension

I have two different app targets (a paid version and a free version) that use the same keyboard extension target. 我有两个使用相同键盘扩展名目标的不同应用程序目标(付费版本和免费版本)。 The only differences between the two app targets of concern to the keyboard are some string values that are currently defined with pre-processor macros. 键盘关注的两个应用程序目标之间的唯一区别是,当前使用预处理器宏定义的一些字符串值。 I need a way to ensure the string values the extension receives are the same as the values received by the source executable. 我需要一种方法来确保扩展接收的字符串值与源可执行文件接收的值相同。

Is it possible for an extension to directly access information about the executable it is packaged with? 扩展是否可以直接访问与打包在一起的可执行文件有关的信息? I could probably manipulate the shared NSUserDefaults on first launch to store the string values for the keyboard but that seems roundabout and unsafe. 我可能可以在首次启动时操纵共享的NSUserDefaults来存储键盘的字符串值,但这似乎是绕行且不安全的。

I was able to accomplish what I needed by checking the bundle identifier like so: 我可以通过检查包标识符来完成所需的工作,如下所示:

#define FOOFree [[[NSBundle mainBundle] bundleIdentifier] containsString:@"free"]

I then use the boolean result of the macro to set the values of the strings for the app and the extension as my extension's bundle identifier has a matching namespace to its source app (which should always be the case if convention is followed). 然后,我使用宏的布尔结果为应用程序和扩展名设置字符串的值,因为我的扩展名的包标识符具有与其源应用程序匹配的名称空间(如果遵循约定,应该总是这样)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS键盘扩展检测点击 - iOS Keyboard Extension detect tap 在UIInputViewController子类中检测旋转。 键盘扩展 - Detect rotation in UIInputViewController subclass. Keyboard extension 如果用户向上滚动控制中心,如何从iOS键盘扩展中检测到? - How can I detect from iOS Keyboard extension if user scrolled up the Control Center? 从 iOS 键盘扩展检测来电的认可方法是什么? - What’s the approved way to detect an incoming phone call from an iOS keyboard extension? 如何通过在iMessage中点击“发送”等操作从iOS键盘扩展中检测到文本字段被清除? - How to detect from iOS keyboard extension that a textfield is cleared via actions like hitting “Send” in iMessage? 在自定义键盘扩展中检测输入对象视图类型 - Detect input object view type in custom keyboard extension 如何在iOS8键盘扩展中检测iPad方向 - How to detect iPad orientation in iOS8 keyboard extension 防止或检测从iOS 8键盘传递的事件 - Prevent or detect events passed on from iOS 8 keyboard 键盘扩展:是否可以从库存iOS键盘继承功能和UI? - Keyboard Extension: Is it possible to inherit features and UI from the stock iOS keyboard? 图片将从主应用发送到键盘扩展 - Image to be sent to keyboard extension from main app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM