Recently, I developed an Internet of things software, which mainly realizes the communication between App and real devices through Bluetooth connection and reading and writing data. This part has been completed. The idea here is that the product wants users to be able to call up the App through voice control, turn it on and off, and do a variety of other things. The current iPhone, the quick thought is through Siri, after all, Apple’s father has opened up the relevant interface.

Project profile

  1. Siri command successfully aroused, directly start the App, in the App independent process to deal with the relevant command operation;
  2. Siri command successfully aroused, do not start the App, directly in the pop-up extension process to deal with the relevant command operation, such as the system’s message is so processed;

Rapid integration

You can refer to: events. Jianshu. IO/p/f318f49fb… , is skipped here

Integration test problem summary

1. Siri Extension, extension info.plist configuration problem

Test 1: Adding a custom intent, as shown above: RelaxIntentIntent;

Result 1: When the command is evoked, the App will not be directly redirected, but an extension interface will pop up for processing, without user authorization;

Test 2: If no custom intents are added;

Result 2: When the shortcut command is evoked, iOS15 versions can directly jump to the App; IOS15.0 ~15.1 between the version of the execution of each quick command, will remind authorization to open, authorization can be opened; However, when the phone was upgraded to 15.1, it was magically found that the shortcut command authorization of the same application was only reminded for the first time.

2. Siri invokes extensions, shortcuts click to open extensions, and the App is in three separate processes

Cause problems:

  • Global cache data cannot be shared.
  • The singleton management class cannot be shared.
  • Persistent data such as userDefault should be used by App Groups association.

Summary and Reflection

If there is no need to deal with bluetooth life cycle (scan, connect, disconnect, read and write) and similar closed-loop business logic, scheme 2 is obviously more convenient and fast, which can be realized without opening App. For example, call the interface to send a message.

However, in view of the current product needs, I think scheme 1 is more reasonable, the current deficiency is the small version of iOS15.0 ~ 15.1 May exist problems. If scheme 2 is used, it is necessary to maintain a set of Bluetooth services separately in the extension module, because singletons and threads are not interconnected, which will bring some potential problems:

  • Subsequent Extension may not support performance consuming operations such as Bluetooth outside the application.
  • Increased Bluetooth business coupling;
  • Bluetooth connection is mutually exclusive between processes and cannot connect to the same device, which is equivalent to siri extending a device, App cannot connect to this device.

Conclusion: At present, plan 2 has been used to realize the requirements, and plan 1 is considered for reconstruction.

If you have any suggestions for the above questions and opinions, please discuss them in the comments section 🤝