Skip to content

Commit

Permalink
Merge pull request #2 from charlon/feature/safari-vc
Browse files Browse the repository at this point in the history
Working safari controller flow.
  • Loading branch information
charlon committed Oct 30, 2019
2 parents 7ae230f + 1f6cb30 commit 4efd0a4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
4 changes: 4 additions & 0 deletions myuw-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
85B147AA2368CD6E00DE3BFA /* AcademicsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85B147A92368CD6E00DE3BFA /* AcademicsViewController.swift */; };
85B147AC2368CDF200DE3BFA /* ResourcesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85B147AB2368CDF200DE3BFA /* ResourcesViewController.swift */; };
85B147AE2368CE7600DE3BFA /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85B147AD2368CE7600DE3BFA /* HomeViewController.swift */; };
85B147B02369FDC300DE3BFA /* SafariController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85B147AF2369FDC300DE3BFA /* SafariController.swift */; };
85F901A7235E34AE00DA0083 /* ProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85F901A6235E34AE00DA0083 /* ProfileViewController.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -60,6 +61,7 @@
85B147A92368CD6E00DE3BFA /* AcademicsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AcademicsViewController.swift; sourceTree = "<group>"; };
85B147AB2368CDF200DE3BFA /* ResourcesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourcesViewController.swift; sourceTree = "<group>"; };
85B147AD2368CE7600DE3BFA /* HomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewController.swift; sourceTree = "<group>"; };
85B147AF2369FDC300DE3BFA /* SafariController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariController.swift; sourceTree = "<group>"; };
85F901A6235E34AE00DA0083 /* ProfileViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -113,6 +115,7 @@
children = (
854EE08D22F0F9A20042381A /* AppDelegate.swift */,
854EE08F22F0F9A20042381A /* AuthenticationController.swift */,
85B147AF2369FDC300DE3BFA /* SafariController.swift */,
85B147A12368CB0700DE3BFA /* TabViewController.swift */,
854EE09422F0F9A30042381A /* Assets.xcassets */,
854EE09622F0F9A30042381A /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -280,6 +283,7 @@
85B147AA2368CD6E00DE3BFA /* AcademicsViewController.swift in Sources */,
85B147A22368CB0700DE3BFA /* TabViewController.swift in Sources */,
854EE09022F0F9A20042381A /* AuthenticationController.swift in Sources */,
85B147B02369FDC300DE3BFA /* SafariController.swift in Sources */,
85B147A42368CC6500DE3BFA /* AccountsViewController.swift in Sources */,
85B147AE2368CE7600DE3BFA /* HomeViewController.swift in Sources */,
85B147A82368CD3800DE3BFA /* TeachingViewController.swift in Sources */,
Expand Down
5 changes: 3 additions & 2 deletions myuw-ios/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

let authController = AuthenticationController()
let tabController = TabViewController()

let safariController = SafariController()

window = UIWindow(frame: UIScreen.main.bounds)

window?.makeKeyAndVisible()

window?.rootViewController = authController
window?.rootViewController = safariController

return true
}
Expand Down
9 changes: 8 additions & 1 deletion myuw-ios/AuthenticationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

import UIKit
import WebKit
import SafariServices


class AuthenticationController: UINavigationController, WKNavigationDelegate {
class AuthenticationController: UINavigationController, WKNavigationDelegate, SFSafariViewControllerDelegate {

var webView: WKWebView!

Expand Down Expand Up @@ -50,6 +51,10 @@ class AuthenticationController: UINavigationController, WKNavigationDelegate {
// set tabControlleer as rootViewController after login
appDelegate.window!.rootViewController = tabController

} else {

// present the safari controller

}


Expand All @@ -71,4 +76,6 @@ class AuthenticationController: UINavigationController, WKNavigationDelegate {
decisionHandler(.allow)
}



}
51 changes: 51 additions & 0 deletions myuw-ios/SafariController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// SafariController.swift
// myuw-ios
//
// Created by Charlon Palacay on 10/30/19.
// Copyright © 2019 Charlon Palacay. All rights reserved.
//

import Foundation
import UIKit
import SafariServices

class SafariController: UIViewController, SFSafariViewControllerDelegate {

var isLogged = false

override func viewDidLoad() {
super.viewDidLoad()
print("safari control: viewDidLoad")
}

override func viewDidAppear(_ animated: Bool) {

print("safari control: viewDidAppear")
print("isLogged", isLogged)

if isLogged {
// tabController (main) and appDelegate instance
let tabController = TabViewController()
let appDelegate = UIApplication.shared.delegate as! AppDelegate
// set tabControlleer as rootViewController after login
appDelegate.window!.rootViewController = tabController
} else {
let url = URL(string: "https://my-test.s.uw.edu/")!
let svc = SFSafariViewController(url: url)
svc.delegate = self
present(svc, animated: false)
}

}

// Called on "Done" button
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
print("done clicked")
dismiss(animated: false, completion: nil)
isLogged = true
}



}

0 comments on commit 4efd0a4

Please sign in to comment.