Переглянути джерело

Merge pull request #406 from deltachat/delta_login

Delta login
björn petersen 5 роки тому
батько
коміт
f67d0193c8

+ 7 - 0
deltachat-ios/AppDelegate.swift

@@ -47,6 +47,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         if let params = url.queryParameters, let token = params["code"] {
             NotificationCenter.default.post(name: NSNotification.Name("oauthLoginApproved"), object: nil, userInfo: ["token": token])
         }
+
+        // Hack to format url properly
+        let urlString = url.absoluteString
+                       .replacingOccurrences(of: "openpgp4fpr", with: "OPENPGP4FPR", options: .literal, range: nil)
+                       .replacingOccurrences(of: "%23", with: "#", options: .literal, range: nil)
+
+        self.appCoordinator.handleQRCode(urlString)
         return true
     }
 

+ 12 - 3
deltachat-ios/Controller/QrViewController.swift

@@ -77,7 +77,8 @@ class QrViewController: UITableViewController, QrCodeReaderDelegate {
     }
 
     private lazy var progressAlert: UIAlertController = {
-        let alert = UIAlertController(title: String.localized("one_moment"), message: "TESTMESSAGE", preferredStyle: .alert)
+        var title = String.localized("one_moment")+"\n\n"
+        let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
 
         let rect = CGRect(x: 0, y: 0, width: 25, height: 25)
         let activityIndicator = UIActivityIndicatorView(frame: rect)
@@ -97,7 +98,12 @@ class QrViewController: UITableViewController, QrCodeReaderDelegate {
             let progressView = UIActivityIndicatorView(frame: rect)
             progressView.tintColor = .blue
             progressView.startAnimating()
+            progressView.translatesAutoresizingMaskIntoConstraints = false
             self.progressAlert.view.addSubview(progressView)
+            self.progressAlert.view.addConstraints([
+                progressView.constraintCenterXTo(self.progressAlert.view),
+                progressView.constraintAlignTopTo(self.progressAlert.view, paddingTop: 45)
+            ])
         })
     }
 
@@ -138,8 +144,11 @@ class QrViewController: UITableViewController, QrCodeReaderDelegate {
     //QRCodeDelegate
     func handleQrCode(_ code: String) {
         //remove qr code scanner view
-        if let ctrl = navigationController {
-            ctrl.viewControllers.removeLast()
+        if let ctrl = navigationController,
+            let lastController = ctrl.viewControllers.last {
+                if type(of: lastController) === QrCodeReaderController.self {
+                    ctrl.viewControllers.removeLast()
+                }
         }
 
         let qrParsed: DcLot = self.dcContext.checkQR(qrCode: code)

+ 9 - 0
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -97,6 +97,15 @@ class AppCoordinator: NSObject, Coordinator {
         navController.pushViewController(chatVC, animated: true)
     }
 
+    func handleQRCode(_ code: String) {
+        showTab(index: qrTab)
+        if let navController = qrController as? UINavigationController,
+            let topViewController = navController.topViewController,
+            let qrViewController = topViewController as? QrViewController {
+            qrViewController.handleQrCode(code)
+        }
+    }
+
     func presentLoginController() {
         window.rootViewController = loginController
         window.makeKeyAndVisible()

+ 5 - 0
deltachat-ios/Info.plist

@@ -21,9 +21,14 @@
 	<key>CFBundleURLTypes</key>
 	<array>
 		<dict>
+			<key>CFBundleTypeRole</key>
+			<string>Editor</string>
+			<key>CFBundleURLName</key>
+			<string>chat.delta.qr</string>
 			<key>CFBundleURLSchemes</key>
 			<array>
 				<string>chat.delta</string>
+				<string>openpgp4fpr</string>
 			</array>
 		</dict>
 	</array>