background
You need to Extension
jump to the main when you click App
, the data transfer is not considered for the time being, only if the main is pulled up App
.
At the end of the day we still need to use UIApplication
the openURL:
method to open the main App
, but this API
limitation Extension
is used in
solve
Does the Extension need an interface
What I did initially was Action Extension
that there were two types when I created it, with an interface and without an interface. Which one to choose to create? Further analysis is required.
Then we have only one idea, which is Runtime
to call openURL:
.
Then you need to find UIApplication
the object first, and Extension
it is also forbidden to use it directly in it.
UIApplication
Since it cannot be used directly, we can find the object through the responder chain and get the object perform openURL
. Then in order to find the object in the responder chain, you UIApplication
must choose a type with an interface to create it.
how to findUIApplication
func openApp(url: URL) {
var responder = self as UIResponder?
while (responder != nil && !(responder is UIApplication)) {
responder = responder?.next
}
if responder != nil {
let selectorOpenURL = sel_registerName("openURL:")
if responder!.responds(to: selectorOpenURL) {
responder?.perform(selectorOpenURL, with: url)
}
}
}
复制代码
At this point, the problem of opening the App has been solved, and you only need to use App Group
it to transmit data.