iOS利用剪切板在app中傳遞信息


利用iOS剪切板在app中傳遞信息

 

App1 中添加URLSchemes   app1

App2 中國添加URLSchemes   app2

 

App1中進入app2:

UIApplication.shared.open(URL(string: "App2://getData")!, options: [:], completionHandler: nil)

app2中在appadelegate中

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

        if url.absoluteString.hasSuffix("getData"){

 

                let pasteboard = UIPasteboard(name: .init("KmyPasteboard"), create: true)

                pasteboard!.string = “需要傳的數據信息”

            }

            

            if #available(iOS 10.0, *) {

                UIApplication.shared.open(URL(string: "App1://getData")!, options: [:], completionHandler: nil)//返回app1

            } else {

                // Fallback on earlier versions

            }

        }

return true

}

返回進入app1后

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

        if url.absoluteString.hasSuffix("getData") {

            let pasteboard = UIPasteboard(name: .init("KmyPasteboard"), create: true)

            let jsonStr = pasteboard!.string

            pasteboard!.string = “”//清空剪切板

            NotificationCenter.default.post(name: NSNotification.Name("Active"), object: jsonStr)

        }

        return true

    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM