All to known,On iOS since 8.0 Start version,Keyboard can be developed for iOS third-party input method,These keyboards can be sold on the AppStore,but,But also has a very strict access rules。
This,Apple's third-party keyboard design of the two permissions,A minimum of,Permissions Only the most basic functions of the keyboard、Another relatively more,Get the keyboard "Full Access"Basically after permission and android Almost on the keyboard,You can access contacts、It can be networked, etc.。
but,Many keyboard function is to set up a user had to request the "full access",Because they found,Failure to do so,As a plug-in keyboard can not access a host app storage space。
In the ios,Although your keyboard in the form of a app to sell and use,But the keyboard is actually a "plug-in",It consists of a single load ios,So in fact it and your app is "two different applications.",They have a separate storage space。
If you give it time to develop a user does not request full access to the keyboard,You'll need to add an additional button in the keyboard,And an interface to set the keyboard properties。And this application app,Then add some empty beginners guide and so on hastily。
For example,
Relatively old Larry input SPI is doing,Its app in novice guide and user forums,Is provided on the keyboard has specialized keys:
Really no way to it?
In fact, it is there,There is a development in the ios called "AppGroup" Technology,It can give the same developers of groups playing different app,Provide a common storage space for these app,In this case between different applications a developer can be exchanged with some configuration files or,To provide users with better services - such as configuration information。
Speaking Nothing special
Apple uses a third-party keyboard AppGroup start is no limit,We can say that this is a bug - use AppGroup keyboard without getting full access,You can also transfer the collected information to go,But after ios10,They perfected the authority,- The keyboard can only be read but not write to the contents of the shared space AppGroup。
But the good news,We can do so that control of the keyboard app。You have thought of,Just put the configuration file in a shared directory,Then take the initiative to read keyboard enough。
So how do some of the newer problems? For example, I can detect whether a file exists,I can load the configuration information,However, if a thesaurus,It just content changed ......
If every line and come back from a shared space,It will be very resource-intensive,So I used the mechanism of a "version number",Every additional proofread it。
This is why a certain point after a start pocketed input method requires the user to configure the complete "return",Because it will trigger an updated version,Keyboard will read。
Thus in simple,But doing it is more complicated - or tedious,You need to preserve the unity part serialization and de-serialization of the tools in the app and keyboard,Here I myself used a single model to specialized management rather than their own access。(Note that you can not use lazy loading,Although the benefits of this feature infinity,But you do it occasionally difficult to change the configuration will lead to,The life cycle of the keyboardUnpredictable - Despite the generally hide keyboard After five seconds)。
Code CI Hou
Here I put my snippet posted to you:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/** 获取的路径为 app groups 共享路径 - parameter fileName: 文件名 - returns: 共享目录的路径 */ class func get(groupPath fileName: String) ->String { let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.logcg.Input") let fileUrl = url?.appendingPathComponent(fileName) return fileUrl!.path } |
Paths can use this method in the application and in the keyboard to get the AppGroup,Only the keyboard is read-only,And this application has full read and write access。
Other configuration and the general reader makes no difference,You should pay attention,You can also write to the configuration,But this is not valid - the point isThere will be no errorsprompt。
1 2 3 4 5 6 7 8 9 10 11 12 |
func getConfig() { let array = NSArray(contentsOfFile: configPath) if array == nil { return } let configDict = array![0] as! Dictionary<String, AnyObject> if let i = configDict["CustomCodeTableVersion"] {customCodeTableVersion = i as! Int} if let e = configDict["EmojiMode"] {emojiMode = e as! Int} if let i = configDict["AssistCodeVersion"] {assistCodeVersion = i as! Int} if let b = configDict["BoomIsLeft"] {boomIsLeft = b as! Bool} if let i = configDict["AssistCodePlan"] {assistCodePlan = i as! Int} if let i = configDict["CodeTableVersion"] {codeTableVersion = i as! Int} } |
Summarize
In fact, search dogs also use this method of,After all, do not open full access to the case,Sogou can still use the application for the basic configuration of the keyboard - you should pay attention to,In ios 10 Previous versions,The keyboard iscanTo share spaceWriteof,I would mention such a。
Original article written by LogStudio:R0uter's Blog » Pocketed input method is how to achieve app settings without the need for full access?
Reproduced Please keep the source and description link:https://www.logcg.com/archives/2488.html