0

My timer is not working...can anyone help me?

I use timer to convert to next page if user login success, but timer is not work and no error message...

do {
                        if let convertedJsonIntoDict = try JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary {
                            // Print out dictionary
                            print("convertedJsonIntoDict=\(convertedJsonIntoDict)")
                            print("convertedJsonIntoDict.長度=\(convertedJsonIntoDict.count)")
                            // Get value by key
                            if convertedJsonIntoDict.count > 1{
                                let cc_account = convertedJsonIntoDict["Account"] as! String
                                self.NPaccount = cc_account
                                print("工號=\(self.NPaccount)")
                                let cc_account_2 = convertedJsonIntoDict["Account2"] as! String
                                self.Account = cc_account_2
                                print("帳號=\(self.Account)")
                                let cname = convertedJsonIntoDict["CName"] as! String
                                self.Name = cname
                                print("姓名=\(self.Name)")
                                self.Member.account = self.Account
                                self.Member.password = self.PasswordTextvield.text!
                                self.Member.npaccount = self.NPaccount
                                self.Member.name = self.Name
                                self.Member.uuid = self.UUID
                                self.Member.creatdate = self.now
                                print("Saving data to context...")
                                appDelegate.saveContext()
                                self.segueflag = true
                                EZLoadingActivity.hide(true, animated: true)
                                _ = Timer.scheduledTimer(timeInterval: 1.5, target: self, selector: #selector(self.nextBtn(sender:)), userInfo: nil, repeats: false)
                            }else{
                                self.segueflag = false
                                print("segueflag...\(self.segueflag)")
                                if !self.segueflag{
                                    print("無此帳號資料...")
                                    EZLoadingActivity.hide(false, animated: true)
                                    //self.AccoubtTextvield.text = ""
                                    //self.PasswordTextvield.text = ""
                                }
                            }
                        }
                        else{
                            print("here")
                        }
                    } catch let error as NSError {
                        print(error.localizedDescription)
                    }

@IBAction func nextBtn(sender: AnyObject) {
        print("--------Go to next page!--------")
        if members.count == 0{
            SCLAlertView().showError("請先登入~~!!",subTitle:"")
            return
        }
        if !segueflag{
            SCLAlertView().showError("登入的帳號或密碼有誤~~!!",subTitle:"")
            return
        }
        self.performSegue(withIdentifier: "login", sender: self)
    }

Can any one tell me possible answer. Thank you in advance....

1
  • 1
    Why you don't use a closure to notify your method has ended? and call your desired action?, using a timer is a very bad approach to do this, you can post your complete code for this method? Commented Mar 31, 2017 at 9:40

1 Answer 1

3

Timer method is change for ios10. If you are checking in ios10 you can use following code.

   let systemVersion = UIDevice.current.systemVersion

        if Int(systemVersion)! >= 10 {
            _ = Timer.scheduledTimer(withTimeInterval: 1.5,
                                         repeats: false) {
                                            timer in
                                            //Put the code that be called by the timer here.
                                            print("Testing data")
            }
        }else{

            _ = Timer.scheduledTimer(timeInterval: 1.5, target: self, selector: #selector(self.nextBtn(sender:)), userInfo: nil, repeats: false)

        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.