Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ios native modules: Expose "AppIdentifierPrefix" (Team ID plus a dot).
Following discussion [1] about a SO answer (not currently the accepted one) [2], we find it's not too hard, when we want the App ID prefix (the Team ID plus a dot), to 1. Add a custom entry in ios/ZulipMobile/Info.plist that gets set to that string at build time, and 2. Write some minimal Objective-C to add a native module that calls an iOS API to grab that custom entry and exposes it to the JavaScript. We followed a very clear React Native doc [3] on how to do this. We also considered using a different doc [4] that would have helped us package our code up very conveniently for distribution to NPM, with a third-party tool called `create-react-native-module`. The output of that tool seemed to have all the appropriate metadata that we're used to seeing in modules in the React Native ecosystem, such as a "podspec" file. But our goal isn't to distribute this code for wide use. Still, it would be possible to, e.g., host it on GitHub (or even locally) and point to it from `dependencies` in our `package.json`. But this seems like a lot more overhead than it'll ever be worth, and we avoided doing something like that in 0b84717, an already-merged part of issue zulip#4124, where we just wrote some Kotlin code and a few lines in our `MainApplication.java` to import it. We put the two new files in the same directory that has `UtilManager.h` and `UtilManager.m`, which were also created for Zulip-specific needs. This time, we follow the pattern of adding a short, all-caps prefix, ZLP, as seen in - Expo -> EX - Unimodules -> UM - React Native -> RCT To link the new files, we used the Xcode UI: 1. Found the PBXGroup called "ZulipMobile" in the left sidebar. In Xcode 11.5, it has a folder icon. It includes the `Info.plist` as well as `UtilManager.h` and `UtilManager.m`. 2. Right-clicked it and selected `Add files to "ZulipMobile"...`, and chose those files. 3. Selected the ZulipMobile target in the project and targets list, and went to Build Phases -> Compile Sources to add the files there. 4. Saw that, surprisingly, they were already added there. So, job done. Then, we tested with some in-app logging to see that we can indeed access the App ID prefix. With NativeModules imported from react-native, we see it at `NativeModules.ZLPInfoProperties.appIdentifierPrefix`. [1]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20native.20module/near/916750 [2]: https://stackoverflow.com/a/28714850/6792075 [3]: https://reactnative.dev/docs/0.60/native-modules-ios [4]: https://reactnative.dev/docs/0.60/native-modules-setup
- Loading branch information