从我的应用程序中打开 IOS 翻译应用程序

问题描述 投票:0回答:0

我正在尝试打开默认的 iOS 翻译应用程序并向其传递一个字符串,以便我可以翻译文本。我有以下代码:

if let text = "Hello, how are you?" as? NSString {
   let encodedText = text.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
   let urlString = "translate://?text=\(encodedText)"
   if let url = URL(string: urlString) {
      UIApplication.shared.open(url, options: [:], completionHandler: nil)
   } else {
      print("Error")
   }
} else {
   print("Error")
}

但这给了我以下错误:

无法打开 URL translate://?text=Hello,%20how%20are%20you%3F: Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)" UserInfo={_LSLine=244, _LSFunction=-[_LSDOpenClient openURL:文件句柄:选项:完成处理程序:]}

任何帮助将不胜感激!

ios swift uiapplication
© www.soinside.com 2019 - 2024. All rights reserved.