有两个测试应用程序称为 Sender & Receiver
它们通过 Url Scheme 相互通信。我想从 Sender 向 Receiver 发送一个字符串,这可能吗?
关于字符串的详细信息:
我都在发件人和收件人中创建文本字段,我会在发件人文本字段上发送一些字符串。当我单击按钮时,字符串将显示在接收方文本字段上。
看来我必须在我的 Apps Receiver 中实现 NSNotificationCenter.defaultCenter().postNotificationName
这是我的应用程序接收器代码:
在 Appdelegate 中
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 的信息
希望能得到一些建议!