Selaa lähdekoodia

Merge pull request #460 from deltachat/open-url

add option to open urls scanned from qr-codes, recognize more qr-codes
cyBerta 5 vuotta sitten
vanhempi
commit
bac701416f
1 muutettua tiedostoa jossa 37 lisäystä ja 0 poistoa
  1. 37 0
      deltachat-ios/Controller/QrViewController.swift

+ 37 - 0
deltachat-ios/Controller/QrViewController.swift

@@ -150,12 +150,49 @@ class QrViewController: UITableViewController, QrCodeReaderDelegate {
             let groupName = qrParsed.text1 ?? "ErrGroupName"
             let groupName = qrParsed.text1 ?? "ErrGroupName"
             joinSecureJoin(alertMessage: String.localizedStringWithFormat(String.localized("qrscan_ask_join_group"), groupName), code: code)
             joinSecureJoin(alertMessage: String.localizedStringWithFormat(String.localized("qrscan_ask_join_group"), groupName), code: code)
 
 
+        case DC_QR_FPR_WITHOUT_ADDR:
+            let msg = String.localized("qrscan_no_addr_found") + "\n\n" +
+                String.localized("qrscan_fingerprint_label") + ":\n" + (qrParsed.text1 ?? "")
+            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+            present(alert, animated: true, completion: nil)
+
+        case DC_QR_FPR_MISMATCH:
+            let nameAndAddress = DcContact(id: qrParsed.id).nameNAddr
+            let msg = String.localizedStringWithFormat(String.localized("qrscan_fingerprint_mismatch"), nameAndAddress)
+            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+            present(alert, animated: true, completion: nil)
+
+        case DC_QR_ADDR, DC_QR_FPR_OK:
+            let nameAndAddress = DcContact(id: qrParsed.id).nameNAddr
+            let msg = String.localizedStringWithFormat(String.localized(state==DC_QR_ADDR ? "ask_start_chat_with" : "qrshow_x_verified"), nameAndAddress)
+            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
+                let chatId = self.dcContext.createChat(contactId: qrParsed.id)
+                self.coordinator?.showChat(chatId: chatId)
+            }))
+            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default, handler: nil))
+            present(alert, animated: true, completion: nil)
+
         case DC_QR_TEXT:
         case DC_QR_TEXT:
             let msg = String.localizedStringWithFormat(String.localized("qrscan_contains_text"), qrParsed.text1 ?? "")
             let msg = String.localizedStringWithFormat(String.localized("qrscan_contains_text"), qrParsed.text1 ?? "")
             let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
             let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
             alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
             present(alert, animated: true, completion: nil)
             present(alert, animated: true, completion: nil)
 
 
+        case DC_QR_URL:
+            let url = qrParsed.text1 ?? ""
+            let msg = String.localizedStringWithFormat(String.localized("qrscan_contains_url"), url)
+            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("open"), style: .default, handler: { _ in
+                if let url = URL(string: url) {
+                    UIApplication.shared.open(url)
+                }
+            }))
+            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default, handler: nil))
+            present(alert, animated: true, completion: nil)
+
         default:
         default:
             var msg = String.localizedStringWithFormat(String.localized("qrscan_contains_text"), code)
             var msg = String.localizedStringWithFormat(String.localized("qrscan_contains_text"), code)
             if state == DC_QR_ERROR {
             if state == DC_QR_ERROR {