2017-04-01 42 views
1

我正在構建一個iOS框架,它應該提供一些常見的模塊,如註冊表,忘記密碼,登錄和配置文件等。因此,任何導入我的框架的應用程序應該能夠使用這些屏幕就是這樣。我面臨的挑戰是在iOS框架代碼中從一個屏幕導航到另一個屏幕。當從屏幕登錄(screen1)導航到另一個屏幕Forgot Password(screen2)時,處理器(回調)方法正在screen1視圖控制器中調用,而不是screen2視圖控制器。我們嘗試使用xib和storyboard,但是我沒有找到解決方案。如何實現登錄模塊作爲我的iOS框架的一部分

有人可以指出任何示例代碼做類似的東西嗎?

我在理解iOS概念時錯過了一些東西,我正在構建一個包含一些UI流的iOS框架,這有可能嗎?

+0

有人可以幫忙嗎? – Swamy

+0

你試過[這](https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/6.3/authentication-security/custom-authenticator-login-module/custom-authenticator-login-module-native-ios-應用程序/)已經? –

回答

2

我會建議一個委託模式,因爲回調更爲一次性,而委託更好地服務於持續幫助對象的生命週期的目的。無論如何,我已經創建了一個例子來應對你的要求,git它here(框架+測試應用程序包括)

它涉及一個LoginController,這是框架的主要入口點和管絃樂隊。

當你初始化它時,你會傳遞一個回調函數來發送事件,包括「忘記密碼」和「用戶想退出」,這些都是在枚舉中定義的。

public enum LoginFrameworkStatus { 
    case Login 
    case ForgotPassword 
    case Help 
    case Disaster 
    case Exited 
    case UserWantsExit 
} 

類提供了一個入口點啓動進程:

public func enterLoginWorkflow(on controller: UIViewController, callback: LoginFrameworkCallback) { 
    let myBundle = Bundle(for: LoginController.self) 

    if let navi = UIStoryboard(name: "LoginWorkflow", bundle: myBundle).instantiateInitialViewController() as? MySpecialNavigationController { 
     presentingController = controller 
     navi.loginController = self 
     self.callback = callback 
     controller.present(navi, animated: true, completion: { 
      //presented! 
      callback?(.Login, navi, self) //If reference to LoginController is lost, tell the callback there's a problem.. shouldn't happend because we have a strong reference on the navigation controller. 
     }) 
     } 
    } 

..和退出點:

public func leaveLoginWorkflow() { 
    presentingController?.dismiss(animated: true, completion: { 
     self.callback?(.Exited, nil,self) 
    }) 
} 

因此,對於你的框架的主界面將是:

LoginController().enterLoginWorkflow(on: self) { (status, controller, loginController) in 
      print("\(status) in \(controller?.description ?? "No Controller")") 

      switch status { 
      case .UserWantsExit: 
       loginController?.leaveLoginWorkflow() 
      case .ForgotPassword: 
       loginController?.leaveLoginWorkflow() 
      default: 
       () 
      } 
     } 

在測試應用程序中我包含最低工作流程供您測試。

讓我知道這是你需要什麼,或者如果你想調查委託模式,我認爲這會更適合這個。

+0

我想賺取這種賞金,所以,如果有什麼灰色的..讓我知道,我可以幫助。 –

+0

希望你明白了:) – Swamy

1

試試1)IcaliaLabs/LoginKit(https://github.com/IcaliaLabs/LoginKit)。 LoginKit是一種快速簡便的方式,可以將登錄/註冊用戶體驗添加到您的iOS應用。

2) TigerWolf/LoginKit https://github.com/TigerWolf/LoginKit 
相關問題