• <legend id='cptxw'><style id='cptxw'><dir id='cptxw'><q id='cptxw'></q></dir></style></legend>

      <i id='cptxw'><tr id='cptxw'><dt id='cptxw'><q id='cptxw'><span id='cptxw'><b id='cptxw'><form id='cptxw'><ins id='cptxw'></ins><ul id='cptxw'></ul><sub id='cptxw'></sub></form><legend id='cptxw'></legend><bdo id='cptxw'><pre id='cptxw'><center id='cptxw'></center></pre></bdo></b><th id='cptxw'></th></span></q></dt></tr></i><div id='cptxw'><tfoot id='cptxw'></tfoot><dl id='cptxw'><fieldset id='cptxw'></fieldset></dl></div>

        <tfoot id='cptxw'></tfoot>

      1. <small id='cptxw'></small><noframes id='cptxw'>

          <bdo id='cptxw'></bdo><ul id='cptxw'></ul>

        由于“内部"保护级别,初始化程序不可访问

        时间:2023-05-18
        • <i id='wgZzZ'><tr id='wgZzZ'><dt id='wgZzZ'><q id='wgZzZ'><span id='wgZzZ'><b id='wgZzZ'><form id='wgZzZ'><ins id='wgZzZ'></ins><ul id='wgZzZ'></ul><sub id='wgZzZ'></sub></form><legend id='wgZzZ'></legend><bdo id='wgZzZ'><pre id='wgZzZ'><center id='wgZzZ'></center></pre></bdo></b><th id='wgZzZ'></th></span></q></dt></tr></i><div id='wgZzZ'><tfoot id='wgZzZ'></tfoot><dl id='wgZzZ'><fieldset id='wgZzZ'></fieldset></dl></div>

              <tfoot id='wgZzZ'></tfoot>

              <small id='wgZzZ'></small><noframes id='wgZzZ'>

                <legend id='wgZzZ'><style id='wgZzZ'><dir id='wgZzZ'><q id='wgZzZ'></q></dir></style></legend>

                  <tbody id='wgZzZ'></tbody>

                  <bdo id='wgZzZ'></bdo><ul id='wgZzZ'></ul>
                • 本文介绍了由于“内部"保护级别,初始化程序不可访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一些协议

                  登录策略

                  public protocol LoginStrategy {
                      func login(_ viewController: UIViewController)
                      func getUserInfo(withCompletionHandler completionHandler: @escaping (_ userInfo: [String: Any]?) -> ())
                      func createLoginButton(_ frame: CGRect, withCompletionHandler completionHandler: @escaping (_ loginButton: UIView) -> ())
                      func getUserId() -> String
                  }
                  

                  还有两个类:

                  登录提供者

                  public class LoginProvider {
                  
                      public let strategy: LoginStrategy
                  
                      public func login(_ viewController: UIViewController) {
                          return self.strategy.login(viewController)
                      }
                  
                      public func getUserInfo(withCompletionHandler completionHandler: @escaping (_ userInfo: [String: Any]?) -> ()) {
                          return self.strategy.getUserInfo(withCompletionHandler: completionHandler)
                      }
                  
                      public func createLoginButton(_ frame: CGRect, withCompletionHandler completionHandler: @escaping (_ loginButton: UIView) -> ()) {
                          return self.strategy.createLoginButton(frame, withCompletionHandler: completionHandler)
                      }
                  
                      public func getUserId() -> String {
                          return self.strategy.getUserId()
                      }
                  
                      public init(strategy: LoginStrategy) {
                          self.strategy = strategy
                      }
                  
                  }
                  

                  FacebookLoginStrategy

                  import Foundation
                  import FacebookCore
                  import FacebookLogin
                  
                  public class FacebookLoginStrategy: LoginStrategy {
                  
                      public var grantedPermissions: Set<Permission>? = nil
                  
                      public var declinedPermissions: Set<Permission>? = nil
                  
                      public var userId: String = ""
                  
                      public func login(_ viewController: UIViewController) {
                          let loginManager = LoginManager()
                          let permissions: [ReadPermission] = [.publicProfile, .userFriends, .email]
                          loginManager.logIn(permissions, viewController: viewController) { loginResult in
                              switch loginResult {
                              case .failed(let error):
                                  print(error)
                              case .cancelled:
                                  print("User cancelled login.")
                              case .success(let grantedPermissions, let declinedPermissions, let accessToken):
                                  self.userId = accessToken.userId ?? ""
                                  self.grantedPermissions = grantedPermissions
                                  self.declinedPermissions = declinedPermissions
                                  print("Logged in!")
                              }
                          }
                      }
                  
                      public func getUserId() -> String {
                          return userId
                      }
                  
                      public func getUserInfo(withCompletionHandler completionHandler: @escaping (_ userInfo: [String: Any]?) -> ()) {
                          let request = GraphRequest(graphPath: "me", parameters: ["fields":"email, name"], accessToken: AccessToken.current, httpMethod: .GET, apiVersion: FacebookCore.GraphAPIVersion.defaultVersion)
                          request.start { (response, result) in
                              switch result {
                              case .success(let value):
                                  print(value.dictionaryValue)
                                  completionHandler(value.dictionaryValue)
                              case .failed(let error):
                                  print(error)
                              }
                          }
                      }
                  
                      public func createLoginButton(_ frame: CGRect, withCompletionHandler completionHandler: @escaping (_ loginButton: UIView) -> ()) {
                          let permissions: [ReadPermission] = [.publicProfile, .userFriends, .email]
                          let loginButton = LoginButton(readPermissions: permissions)
                          loginButton.frame = frame
                          completionHandler(loginButton)
                      }
                  }
                  

                  在我的 ViewController 中:

                  当我使用时:

                  let facebookLoginProvider = LoginProvider(strategy: FacebookLoginStrategy())
                  

                  上面写着:

                  FacebookLoginStrategy"由于内部"保护而无法访问等级

                  'FacebookLoginStrategy' is inaccessable due to 'internal' protection level

                  推荐答案

                  只需添加到您的 FacebookLoginStrategy:

                  Just add to your FacebookLoginStrategy:

                  public init() {}
                  

                  只要你没有显式地实现 init(),它就会被默认标记为内部的.您需要覆盖该权限级别才能从框架外部进行实例化.

                  As long as you do not implement init() explicitly, it is marked as internal by default. You need to overwrite that permission level to be able to instantiate from outside your framework.

                  这篇关于由于“内部"保护级别,初始化程序不可访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 Mantle 在 NSArray 中指定子对象类型 下一篇:我可以在编译和链接时将 C++ 主函数和类与 Objective-C 和/或 C 例程分开吗?

                  相关文章

                  <i id='wj3oX'><tr id='wj3oX'><dt id='wj3oX'><q id='wj3oX'><span id='wj3oX'><b id='wj3oX'><form id='wj3oX'><ins id='wj3oX'></ins><ul id='wj3oX'></ul><sub id='wj3oX'></sub></form><legend id='wj3oX'></legend><bdo id='wj3oX'><pre id='wj3oX'><center id='wj3oX'></center></pre></bdo></b><th id='wj3oX'></th></span></q></dt></tr></i><div id='wj3oX'><tfoot id='wj3oX'></tfoot><dl id='wj3oX'><fieldset id='wj3oX'></fieldset></dl></div>

                • <legend id='wj3oX'><style id='wj3oX'><dir id='wj3oX'><q id='wj3oX'></q></dir></style></legend><tfoot id='wj3oX'></tfoot>
                      <bdo id='wj3oX'></bdo><ul id='wj3oX'></ul>

                  1. <small id='wj3oX'></small><noframes id='wj3oX'>