调用默认委托实现以及用户定义的方法

时间:2016-10-04 05:37:42

标签: ios delegates

我正在实施GoogleSignInDelegate进行身份验证。我已经实现了GoogleSignIn委托方法。我想在其中一个方法中添加UIActivityIndi​​cator并使用相同的现有实现。任何想法我该怎么做?

1 个答案:

答案 0 :(得分:0)

在我的注册控制器中,我实现了委托方法。

 // MARK: GIDSignInDelegates.

    func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {

        showProgressBarIndicator()

        if (error == nil) {

            let params = [
                "access_token"  :   user.authentication.accessToken,
                "email"         :   user.profile.email,
                "name"          :   user.profile.name,
                "photoUrl"      :   user.profile.imageURLWithDimension(100).absoluteString,
                "profile_url"   :   user.profile.imageURLWithDimension(100).absoluteString,
                "provider"      :   Provider.GooglePlus.rawValue,
                "provider_id"   :   user.authentication.clientID
            ]

            AFWrapper.requestPOSTURL(BaseUrl + ApiMethod.SignUp.rawValue, params: params,

                success: {(JSONResponse) -> Void in
                    self.saveDataToDisk(JSONResponse)
                },

                failure: { (error) -> Void in
                    dispatch_async(dispatch_get_main_queue(), {
                        self.removeProgressBarIndicator()
                        JLToast.makeText("Connection Error!").show()
                    })
                }
            )
        } else {
            dispatch_async(dispatch_get_main_queue(), {
                self.removeProgressBarIndicator()
                JLToast.makeText("Error in getting data from Google!").show()
            })

        }
    }

和我的基本控制器我有以下方法。

func showProgressBarIndicator() {

        container.frame = self.view.frame
        container.center = view.center
        container.backgroundColor = UIColor(colorLiteralRed: 255.0, green: 255.0, blue: 255.0, alpha: 0.7)

        let loadingView: UIView = UIView()
        loadingView.frame = CGRectMake(0, 0, 80, 80)
        loadingView.center = view.center
        loadingView.backgroundColor = UIColor(colorLiteralRed: 0.0, green: 0.0, blue: 0.0, alpha: 0.7)
        loadingView.clipsToBounds = true
        loadingView.layer.cornerRadius = 10

        let activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
        activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
        activityIndicator.activityIndicatorViewStyle =
            UIActivityIndicatorViewStyle.WhiteLarge
        activityIndicator.center = CGPointMake(loadingView.frame.size.width / 2,
                                               loadingView.frame.size.height / 2);
        activityIndicator.startAnimating()
        loadingView.addSubview(activityIndicator)

        container.addSubview(loadingView)
        self.view.addSubview(container)
    }


func removeProgressBarIndicator() {
        if !container.isDescendantOfView(self.view) {
            self.container.removeFromSuperview()
        }
    }