[英]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.