有两个测试应用程序称为发件人&接收器在swift中通过url方案在两个应用之间传递数据?
它们通过Url Scheme相互沟通。我想从Sender发送一个字符串到Receiver,这可能吗?
详细了解字符串:
我都在发件人创建文本框和接收器,我将文字发件人文本字段的一些字符串。当我点击按钮时,字符串将显示在Receiver Textfield上。
这里是我的应用程序接收代码:
在AppDelegate中
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
calledBy = sourceApplication
fullUrl = url.absoluteString
scheme = url.scheme
query = url.query
}
在的viewController现在
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 like this信息
希望得到一些建议!
完美答案!很酷,在计划之后添加一个查询。 – HungCLo
很好的答案。如果你想传递字符串以外的数据,你应该添加关于base64的信息。 –
很好的答案,很好的解释和一个明确的例子。 – Josh