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

initial commit for delta chat login demo

cyberta 5 роки тому
батько
коміт
396c4e3ed4

+ 8 - 1
deltachat-ios/AppDelegate.swift

@@ -42,11 +42,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         return []
         return []
     }
     }
 
 
-    func application(_: UIApplication, open url: URL, options _: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
+    func application(_: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
         // gets here when app returns from oAuth2-Setup process - the url contains the provided token
         // gets here when app returns from oAuth2-Setup process - the url contains the provided token
         if let params = url.queryParameters, let token = params["code"] {
         if let params = url.queryParameters, let token = params["code"] {
             NotificationCenter.default.post(name: NSNotification.Name("oauthLoginApproved"), object: nil, userInfo: ["token": token])
             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
         return true
     }
     }
 
 

+ 5 - 2
deltachat-ios/Controller/QrViewController.swift

@@ -138,8 +138,11 @@ class QrViewController: UITableViewController, QrCodeReaderDelegate {
     //QRCodeDelegate
     //QRCodeDelegate
     func handleQrCode(_ code: String) {
     func handleQrCode(_ code: String) {
         //remove qr code scanner view
         //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)
         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)
         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() {
     func presentLoginController() {
         window.rootViewController = loginController
         window.rootViewController = loginController
         window.makeKeyAndVisible()
         window.makeKeyAndVisible()

+ 5 - 0
deltachat-ios/Info.plist

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