12

Sender & Receiver と呼ばれる 2 つのテスト アプリがあります。

それらは Url スキームによって相互に通信します。Sender から Receiver に String を送信したいのですが、可能ですか?

文字列に関する詳細:

Sender と Receiver の両方で Textfields を作成し、Sender Textfield に文字列をテキストで送信します。ボタンをクリックすると、文字列がレシーバ テキスト フィールドに表示されます。

Apps 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
}

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に関する情報しか表示できません

画像2

いくつかの提案を得ることを願っています!

4

2 に答える 2