美文网首页
iOS open url 传值回调

iOS open url 传值回调

作者: 小奉不在乎 | 来源:发表于2018-11-16 15:57 被阅读0次

简单说说吧,open url传值这个网上教程确实不少,关键是都没有说道关键点子上,把值从A传到B容易,再传回来的时候就尴尬了吧,求人不如求己,我就简单记录下吧。废话少说,直接开干。

  1. 新建两个Demo一个为Demo1,一个为Demo2,同时打开倒开info,添加一项URL types为自己的URL Scheme
image.png image.png
  1. 确定谁给谁传值,就Demo1给给Demo2吧,然后在demo1中把demo2添加为白名单。


    image.png
  2. 搞事情了,在demo1中加个Button然后牵条线整个点击事件试试,顺带传点值

 @IBAction func btnClick(_ sender: Any) {
        
        /// 如果有中文就用
        /// addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)转一下就好了
        let stringUrl = "Demo2://testContent?id=0&title=test&content=testETH&scheme=Demo1"
        
        if let url = URL(string: stringUrl) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
    }
  1. 再demo2中的AppDelegate.swift中加入下面的代码
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        let stringUrl = "Demo1://testContent?id=6666&title=test&content=testEOS&scheme=Demo2"
        if let url = URL(string: stringUrl) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
        return true
    }
  1. 最后再到demo1中去接收我们修改过后的东西吧,一切都是那么自然
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        
        let s = UIAlertView.init(title: nil, message: url.absoluteString, delegate: nil, cancelButtonTitle: "确定")
        s.show()
        return true
    }

好啦,装逼结束,希望我的朋友路过就点个👍吧,谢谢你们的支持。

相关文章

  • iOS open url 传值回调

    简单说说吧,open url传值这个网上教程确实不少,关键是都没有说道关键点子上,把值从A传到B容易,再传回来的时...

  • 2019-05-07

    //GetPasteboard iOS 回调js传值

  • 回调函数

    1.简单的回调 2. 回调取值 3. 回调传值与取值

  • iOS,Block传值

    iOS页面之间传值,通常采取四种方式:属性、通知、代理和Block回调传值这四种方式。 今天在这里,我们详细讲解B...

  • iOS-block总结

    block回调-传值 其实就是block作为参数传值方:类的.h有block属性,类的.m有block调用(传值,...

  • iOS同步通知和异步通知

    NSNotification 是iOS中一个调度消息通知的类,采用单例模式设计,在程序中实现传值和回调. 一. 和...

  • Block回调传值

    实现回调传值的方式有哪些? 1.block2.delegate3.NSNotificationCenter 1.b...

  • 代理回调传值

    在需要传值的视图接口 声明一个代理 delegate PushViewController.h中代码 PushVi...

  • Android/iOS webview Js 交互

    最近调试一个活动页面,需要app和web端传值。这里iOS讨论的是WKWebView URL传值 最开始我们使用了...

  • iOS NSNotificationCenter

    NSNotification 是iOS中一个调度消息通知的类,采用单例模式设计,在程序中实现传值、回调等地方应用很...

网友评论

      本文标题:iOS open url 传值回调

      本文链接:https://www.haomeiwen.com/subject/miymfqtx.html