有两个测试应用程序称为发送者和接收者
他们通过 UrlScheme 相互通信。我想从发送者发送一个字符串到接收者,这可能吗?
关于字符串的详细信息:
我都在发送者和接收者中创建文本字段,我会在发送者文本字段上发送一些字符串。当我单击按钮时,字符串将显示在接收器文本字段中。
看来我必须在我的 Apps Receiver 中实现 NSNotificationCenter.defaultCenter().postNotificationName https://stackoverflow.com/questions/32824528/inter-app-communication-in-ios-using-url-scheme
这是我的应用程序接收器代码:
在应用程序委托中
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
calledBy = sourceApplication
fullUrl = url.absoluteString
scheme = url.scheme
query = url.query
}
在视图控制器中
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.displayLaunchDetails), name: UIApplicationDidBecomeActiveNotification, object: nil)
// Do any additional setup after loading the view, typically from a nib.
}
func displayLaunchDetails() {
let receiveAppdelegate = UIApplication.sharedApplication().delegate as! AppDelegate
if receiveAppdelegate.calledBy != nil {
self.calledByText.text = receiveAppdelegate.calledBy
}
if receiveAppdelegate.fullUrl != nil {
self.fullUrlText.text = receiveAppdelegate.fullUrl
}
if receiveAppdelegate.scheme != nil {
self.schemeText.text = receiveAppdelegate.scheme
}
if receiveAppdelegate.query != nil {
self.queryText.text = receiveAppdelegate.query
}
}
现在,我只能显示有关 url 的信息像这样 https://stackoverflow.com/questions/32824528/inter-app-communication-in-ios-using-url-scheme
希望能得到一些建议!