What is the life cycle of a third-party input method on the iOS platform?

we just discussed What is the life cycle of third-party input methods on the macOS platform?,Now let's talk about third-party keyboards for the iOS platform while it's hotThe life cycle

On Apple's official website,only this:

Apple has no description of the lifecycle of third-party keyboards

Applethird-party keyboardlife cycle without any description

It seems easy to understand,The life cycle of the keyboard is managed by the system,Every time the user calls out the keyboard,just it starts,User puts away the keyboard,After a while it's wiped out。

But with the previous macOS input methodFramework life cycle experience,Let's look at iOS again,Is it really? in appleIf the developer documentation related pagesthe end of:

  • Keep in mind that dismissing the keyboard won’t necessarily terminate the keyboard extension process. Don’t assume the system releases memory your keyboard is using when it is no longer visible on screen.

This description, which I do not know when it was added, means that:Putting away the keyboard doesn't necessarily end the keyboard process... soextension + backgroundThese two properties make your keyboard process extremely easy to be killed by the system as garbage,Obviously this will trigger an inexplicable crash record...

 

In short,Experience with the macOS input method life cycle,We can know that iOS The processing is not much worse - the system will start the process of the third-party keyboard the first time the keyboard is ejected,Then this process runs in the background all the way (don't think too beautiful,The keyboard doesn't pop up anyway,The vast majority of APIs are invalid.),When user focus is on input box,keyboard pops up,That is to initialize a Controller,Unlike macOS,no here InputSession The,every time the keyboard pops up,will initialize a new Controller,It doesn't matter which app it's in。

- What if the keyboard crashes? This is the same as macOS,reboot now,If it crashes continuously,fall back to an alternate keyboard that comes with the system,Guaranteed user experience。

for a long time,I also thought there was only one Controller,Use a lot of global variables,Obviously,It is impossible for us to display two keyboards at the same time and give input to different input boxes at the same time,This leads to strange bugs such as the Controller finding the wrong way in some extreme cases。And always thought that it was a bug of Xcode Debug that caused the keyboard process not to end automatically when compiling on a real machine。

In short,After understanding this life cycle,memory can be better arranged,And do some memory processing in the background,Ensure that keyboard processes that have not been used for a long time are not killed by the system as garbage。

 

Original article written by Gerber drop-off:R0uter's Blog » What is the life cycle of a third-party input method on the iOS platform?

Reproduced Please keep the source and description link:https://www.logcg.com/archives/3569.html

About the Author

R0uter

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

Leave a Reply

Your email address will not be published. Required fields are marked *