mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-09 21:05:53 +10:00
add YepAlert; show errorMessage when sendVerifyCode failed
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
502AE5331AB86020005BD199 /* RegisterVerifyMobileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 502AE5321AB86020005BD199 /* RegisterVerifyMobileViewController.swift */; };
|
||||
502AE5351AB8649F005BD199 /* LoginByMobileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 502AE5341AB8649F005BD199 /* LoginByMobileViewController.swift */; };
|
||||
502AE5381AB866E3005BD199 /* LoginVerifyMobileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 502AE5371AB866E3005BD199 /* LoginVerifyMobileViewController.swift */; };
|
||||
502AE53A1AB871C1005BD199 /* YepAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 502AE5391AB871C1005BD199 /* YepAlert.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@@ -88,6 +89,7 @@
|
||||
502AE5321AB86020005BD199 /* RegisterVerifyMobileViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RegisterVerifyMobileViewController.swift; path = ViewControllers/Register/RegisterVerifyMobileViewController.swift; sourceTree = "<group>"; };
|
||||
502AE5341AB8649F005BD199 /* LoginByMobileViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LoginByMobileViewController.swift; path = ViewControllers/Login/LoginByMobileViewController.swift; sourceTree = "<group>"; };
|
||||
502AE5371AB866E3005BD199 /* LoginVerifyMobileViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LoginVerifyMobileViewController.swift; path = ViewControllers/Login/LoginVerifyMobileViewController.swift; sourceTree = "<group>"; };
|
||||
502AE5391AB871C1005BD199 /* YepAlert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepAlert.swift; path = Helpers/YepAlert.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -131,6 +133,7 @@
|
||||
children = (
|
||||
5023DE441AB6B19300B3EE96 /* DummyData */,
|
||||
0A8F54B01AB67D11004AD60E /* AppDelegate.swift */,
|
||||
502AE53B1AB871C5005BD199 /* Helpers */,
|
||||
502AE52C1AB819B5005BD199 /* Configs */,
|
||||
502AE5251AB72BE9005BD199 /* Services */,
|
||||
5023DE571AB6CA1400B3EE96 /* Caches */,
|
||||
@@ -334,6 +337,14 @@
|
||||
name = Login;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
502AE53B1AB871C5005BD199 /* Helpers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
502AE5391AB871C1005BD199 /* YepAlert.swift */,
|
||||
);
|
||||
name = Helpers;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
@@ -451,6 +462,7 @@
|
||||
5023DE591AB6DBC100B3EE96 /* UIImage+Yep.swift in Sources */,
|
||||
502AE5331AB86020005BD199 /* RegisterVerifyMobileViewController.swift in Sources */,
|
||||
5023DE2D1AB685ED00B3EE96 /* DiscoverViewController.swift in Sources */,
|
||||
502AE53A1AB871C1005BD199 /* YepAlert.swift in Sources */,
|
||||
502AE52E1AB83879005BD199 /* UnderLineTextField.swift in Sources */,
|
||||
5023DE301AB6861500B3EE96 /* ProfileViewController.swift in Sources */,
|
||||
5023DE261AB6856300B3EE96 /* ConversationsViewController.swift in Sources */,
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// YepAlert.swift
|
||||
// Yep
|
||||
//
|
||||
// Created by NIX on 15/3/17.
|
||||
// Copyright (c) 2015年 Catch Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class YepAlert {
|
||||
class func alert(#title: String, message: String, inViewController viewController: UIViewController, withDismissAction dismissAction: (() -> Void)?) {
|
||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
|
||||
|
||||
let action: UIAlertAction = UIAlertAction(title: NSLocalizedString("Dismiss", comment: ""), style: .Default) { action -> Void in
|
||||
if let dismissAction = dismissAction {
|
||||
dismissAction()
|
||||
}
|
||||
}
|
||||
alertController.addAction(action)
|
||||
|
||||
viewController.presentViewController(alertController, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
class func alertSorry(#message: String, inViewController viewController: UIViewController, withDismissAction dismissAction: () -> Void) {
|
||||
alert(title: NSLocalizedString("Sorry", comment: ""), message: message, inViewController: viewController, withDismissAction: dismissAction)
|
||||
}
|
||||
|
||||
class func alertSorry(#message: String, inViewController viewController: UIViewController) {
|
||||
alert(title: NSLocalizedString("Sorry", comment: ""), message: message, inViewController: viewController, withDismissAction: nil)
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ func errorMessageInData(data: NSData?) -> String? {
|
||||
return nil
|
||||
}
|
||||
|
||||
func sendVerifyCode(ofMobile mobile: String, withAreaCode areaCode: String, #failureHandler: ((Resource<Bool>, Reason, NSData?) -> ())?, completion: Bool -> ()) {
|
||||
func sendVerifyCode(ofMobile mobile: String, withAreaCode areaCode: String, #failureHandler: ((Resource<Bool>, Reason, NSData?) -> ())?, #completion: Bool -> ()) {
|
||||
|
||||
let requestParameters = [
|
||||
"mobile": mobile,
|
||||
|
||||
@@ -54,26 +54,48 @@ class LoginByMobileViewController: UIViewController {
|
||||
|
||||
|
||||
@IBAction func next(sender: UIButton) {
|
||||
showLoginVerifyMobile()
|
||||
tryShowLoginVerifyMobile()
|
||||
}
|
||||
|
||||
private func showLoginVerifyMobile() {
|
||||
private func tryShowLoginVerifyMobile() {
|
||||
|
||||
view.endEditing(true)
|
||||
|
||||
let mobile = mobileNumberTextField.text
|
||||
let areaCode = areaCodeTextField.text
|
||||
|
||||
sendVerifyCode(ofMobile: mobile, withAreaCode: areaCode, failureHandler: nil) { success in
|
||||
if success {
|
||||
println("Verification code sent successfully")
|
||||
sendVerifyCode(ofMobile: mobile, withAreaCode: areaCode, failureHandler: { (resource, reason, data) in
|
||||
defaultFailureHandler(forResource: resource, withFailureReason: reason, data)
|
||||
|
||||
if let errorMessage = errorMessageInData(data) {
|
||||
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||
self.performSegueWithIdentifier("showLoginVerifyMobile", sender: ["mobile" : mobile, "areaCode": areaCode])
|
||||
YepAlert.alertSorry(message: errorMessage, inViewController: self, withDismissAction: { () -> Void in
|
||||
mobileNumberTextField.becomeFirstResponder()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}, completion: { success in
|
||||
if success {
|
||||
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||
self.showLoginVerifyMobile()
|
||||
})
|
||||
|
||||
} else {
|
||||
println("Failed to send verification code")
|
||||
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||
YepAlert.alertSorry(message: NSLocalizedString("Failed to send verification code", comment: ""), inViewController: self, withDismissAction: { () -> Void in
|
||||
mobileNumberTextField.becomeFirstResponder()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func showLoginVerifyMobile() {
|
||||
let mobile = mobileNumberTextField.text
|
||||
let areaCode = areaCodeTextField.text
|
||||
|
||||
self.performSegueWithIdentifier("showLoginVerifyMobile", sender: ["mobile" : mobile, "areaCode": areaCode])
|
||||
}
|
||||
|
||||
// MARK: Navigation
|
||||
@@ -95,7 +117,7 @@ class LoginByMobileViewController: UIViewController {
|
||||
extension LoginByMobileViewController: UITextFieldDelegate {
|
||||
func textFieldShouldReturn(textField: UITextField) -> Bool {
|
||||
if !textField.text.isEmpty {
|
||||
showLoginVerifyMobile()
|
||||
tryShowLoginVerifyMobile()
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user