我試圖讓我的應用程序從qr碼打開掃描的URL。我製作了一款qr碼掃描儀,但它僅將掃描後的qr碼的值複製到粘貼板。我試圖讓它在SFSafariViewController中打開它。 而不是「複製」選項,我想讓它「打開」,並實際上打開掃描的網址。打開從SFSafariViewController中的QR碼掃描的URL
這裏是我的代碼
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {
if metadataObjects != nil && metadataObjects.count != 0
{
if let object = metadataObjects[0] as? AVMetadataMachineReadableCodeObject
{
if object.type == AVMetadataObjectTypeQRCode
{
let alert = UIAlertController(title: "QR Code", message: object.stringValue, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Retake", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "Copy", style: .default, handler: { (nil) in
UIPasteboard.general.string = object.stringValue
}))
present(alert, animated: true, completion: nil)
}
}
}
}
工作!謝謝! 我剛剛離開那裏的「重拍」按鈕,並將「複製」更改爲「打開」,然後調用loadSafari函數。 再次感謝! – Ibrahim
很高興幫助你@Ibrahim。 :) –