有两个名为Sender和Receiver的测试应用程序
它们通过URL方案相互通信。我想从Sender发送一个字符串到Receiver,这可行吗?
关于该字符串的详细信息:
我在Sender和Receiver中都创建了文本字段,我会在Sender文本字段上输入一些字符串。当我单击按钮时,字符串将显示在Receiver文本字段上。
似乎我必须在我的应用程序Receiver中实现NSNotificationCenter.defaultCenter().postNotificationName
这是我的App Receiver代码:
在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的信息像这样