-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3.3.0 release. Alamofire 3.5 / Swift 2.3 full update.
- Loading branch information
Stephen Cobbe
committed
Sep 14, 2016
1 parent
3465fe9
commit ab71ab5
Showing
66 changed files
with
5,203 additions
and
856 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,8 @@ | |
## user-specific settings | ||
xcuserdata/ | ||
|
||
## project dependencies | ||
## CocoaPods | ||
Pods/ | ||
|
||
## Carthage | ||
Carthage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
disabled_rules: # rule identifiers to exclude from running | ||
- colon | ||
- comma | ||
- control_statement | ||
opt_in_rules: # some rules are only opt-in | ||
- empty_count | ||
- missing_docs | ||
# Find all the available rules by running: | ||
# swiftlint rules | ||
included: # paths to include during linting. `--path` is ignored if present. | ||
- Source | ||
excluded: # paths to ignore during linting. Takes precedence over `included`. | ||
- Carthage | ||
- Pods | ||
- Source/ExcludedFolder | ||
- Source/ExcludedFile.swift | ||
|
||
# configurable rules can be customized from this configuration file | ||
# binary rules can set their severity level | ||
force_cast: warning # implicitly | ||
force_try: | ||
severity: warning # explicitly | ||
# rules that have both warning and error levels, can set just the warning level | ||
# implicitly | ||
line_length: 80 | ||
# they can set both implicitly with an array | ||
type_body_length: | ||
- 300 # warning | ||
- 400 # error | ||
# or they can set both explicitly | ||
file_length: | ||
warning: 500 | ||
error: 1200 | ||
# naming rules can set warnings/errors for min_length and max_length | ||
# additionally they can set excluded names | ||
type_name: | ||
min_length: 4 # only warning | ||
max_length: # warning and error | ||
warning: 40 | ||
error: 50 | ||
excluded: iPhone # excluded via string | ||
variable_name: | ||
min_length: # only min_length | ||
error: 4 # only error | ||
excluded: # excluded via string array | ||
- id | ||
- URL | ||
- GlobalAPIKey | ||
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github "https://github.com/Alamofire/Alamofire.git" ~> 3.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github "Alamofire/Alamofire" "3.5.0" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
disabled_rules: # rule identifiers to exclude from running | ||
# - colon | ||
# - comma | ||
# - control_statement | ||
opt_in_rules: # some rules are only opt-in | ||
- empty_count | ||
- missing_docs | ||
# Find all the available rules by running: | ||
# swiftlint rules | ||
included: # paths to include during linting. `--path` is ignored if present. | ||
- Source | ||
excluded: # paths to ignore during linting. Takes precedence over `included`. | ||
- Carthage | ||
- Pods | ||
- Source/ExcludedFolder | ||
- Source/ExcludedFile.swift | ||
|
||
# configurable rules can be customized from this configuration file | ||
# binary rules can set their severity level | ||
force_cast: warning # implicitly | ||
force_try: | ||
severity: warning # explicitly | ||
# rules that have both warning and error levels, can set just the warning level | ||
# implicitly | ||
line_length: | ||
- 50 # warning | ||
- 70 # error | ||
# they can set both implicitly with an array | ||
type_body_length: | ||
- 300 # warning | ||
- 400 # error | ||
# or they can set both explicitly | ||
file_length: | ||
warning: 500 | ||
error: 1200 | ||
# naming rules can set warnings/errors for min_length and max_length | ||
# additionally they can set excluded names | ||
type_name: | ||
min_length: 4 # only warning | ||
max_length: # warning and error | ||
warning: 40 | ||
error: 50 | ||
excluded: iPhone # excluded via string | ||
variable_name: | ||
min_length: # only min_length | ||
error: 4 # only error | ||
excluded: # excluded via string array | ||
- id | ||
- URL | ||
- GlobalAPIKey | ||
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
import Foundation | ||
import UIKit | ||
import WebKit | ||
import SystemConfiguration | ||
|
||
extension Dropbox { | ||
public static func authorizeFromController(sharedApplication: UIApplication, controller: UIViewController, openURL: (NSURL -> Void), browserAuth: Bool = false) { | ||
precondition(DropboxAuthManager.sharedAuthManager != nil, "Call `Dropbox.setupWithAppKey` or `Dropbox.setupWithTeamAppKey` before calling this method") | ||
precondition(Dropbox.authorizedClient == nil && Dropbox.authorizedTeamClient == nil, "A Dropbox client is already authorized") | ||
DropboxAuthManager.sharedAuthManager.authorizeFromSharedApplication(MobileSharedApplication(sharedApplication: sharedApplication, controller: controller, openURL: openURL), browserAuth: browserAuth) | ||
} | ||
|
||
public static func setupWithAppKey(appKey: String) { | ||
setupWithAppKey(appKey, sharedAuthManager: DropboxMobileAuthManager(appKey: appKey)) | ||
} | ||
|
||
public static func setupWithTeamAppKey(appKey: String) { | ||
setupWithTeamAppKey(appKey, sharedAuthManager: DropboxMobileAuthManager(appKey: appKey)) | ||
} | ||
} | ||
|
||
|
||
public class MobileSharedApplication: SharedApplication { | ||
let sharedApplication: UIApplication | ||
let controller: UIViewController | ||
let openURL: (NSURL -> Void) | ||
|
||
public init(sharedApplication: UIApplication, controller: UIViewController, openURL: (NSURL -> Void)) { | ||
// fields saved for app-extension safety | ||
self.sharedApplication = sharedApplication | ||
self.controller = controller | ||
self.openURL = openURL | ||
} | ||
|
||
public func presentErrorMessage(message: String, title: String) { | ||
let alertController = UIAlertController( | ||
title: title, | ||
message: message, | ||
preferredStyle: UIAlertControllerStyle.Alert) | ||
controller.presentViewController(alertController, animated: true, completion: { fatalError(message) }) | ||
} | ||
|
||
public func presentErrorMessageWithHandlers(message: String, title: String, buttonHandlers: Dictionary<String, () -> Void>) { | ||
let alertController = UIAlertController( | ||
title: title, | ||
message: message, | ||
preferredStyle: UIAlertControllerStyle.Alert) | ||
|
||
alertController.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)) | ||
alertController.addAction(UIAlertAction(title: "Retry", style: .Default) { (_) in | ||
buttonHandlers["Retry"]!() | ||
}) | ||
|
||
controller.presentViewController(alertController, animated: true, completion: {}) | ||
} | ||
|
||
public func presentPlatformSpecificAuth(authURL: NSURL) -> Bool { | ||
presentExternalApp(authURL) | ||
return true | ||
} | ||
|
||
public func presentWebViewAuth(authURL: NSURL, tryIntercept: (NSURL -> Bool), cancelHandler: (() -> Void)) { | ||
let web = DropboxConnectController( | ||
URL: authURL, | ||
tryIntercept: tryIntercept, | ||
cancelHandler: cancelHandler | ||
) | ||
let navigationController = UINavigationController(rootViewController: web) | ||
controller.presentViewController(navigationController, animated: true, completion: nil) | ||
} | ||
|
||
public func presentBrowserAuth(authURL: NSURL) { | ||
presentExternalApp(authURL) | ||
} | ||
|
||
public func presentExternalApp(url: NSURL) { | ||
self.openURL(url) | ||
} | ||
|
||
public func canPresentExternalApp(url: NSURL) -> Bool { | ||
return self.sharedApplication.canOpenURL(url) | ||
} | ||
} | ||
|
||
public class DropboxConnectController: UIViewController, WKNavigationDelegate { | ||
var webView: WKWebView! | ||
|
||
var onWillDismiss: ((didCancel: Bool) -> Void)? | ||
var tryIntercept: ((url: NSURL) -> Bool)? | ||
|
||
var cancelButton: UIBarButtonItem? | ||
var cancelHandler: (() -> Void) = {} | ||
|
||
var indicator = UIActivityIndicatorView(activityIndicatorStyle: .Gray) | ||
|
||
public init() { | ||
super.init(nibName: nil, bundle: nil) | ||
} | ||
|
||
public init(URL: NSURL, tryIntercept: ((url: NSURL) -> Bool), cancelHandler: (() -> Void)) { | ||
super.init(nibName: nil, bundle: nil) | ||
self.startURL = URL | ||
self.tryIntercept = tryIntercept | ||
self.cancelHandler = cancelHandler | ||
} | ||
|
||
required public init?(coder aDecoder: NSCoder) { | ||
super.init(coder: aDecoder) | ||
} | ||
|
||
override public func viewDidLoad() { | ||
super.viewDidLoad() | ||
self.title = "Link to Dropbox" | ||
self.webView = WKWebView(frame: self.view.bounds) | ||
|
||
indicator.center = view.center | ||
self.webView.addSubview(indicator) | ||
indicator.startAnimating() | ||
|
||
self.view.addSubview(self.webView) | ||
|
||
self.webView.navigationDelegate = self | ||
|
||
self.view.backgroundColor = UIColor.whiteColor() | ||
|
||
self.cancelButton = UIBarButtonItem(barButtonSystemItem: .Cancel, target: self, action: #selector(DropboxConnectController.cancel(_:))) | ||
self.navigationItem.rightBarButtonItem = self.cancelButton | ||
} | ||
|
||
public override func viewWillAppear(animated: Bool) { | ||
super.viewWillAppear(animated) | ||
if !webView.canGoBack { | ||
if nil != startURL { | ||
loadURL(startURL!) | ||
} else { | ||
webView.loadHTMLString("There is no `startURL`", baseURL: nil) | ||
} | ||
} | ||
} | ||
|
||
public func webView(webView: WKWebView, | ||
decidePolicyForNavigationAction navigationAction: WKNavigationAction, | ||
decisionHandler: (WKNavigationActionPolicy) -> Void) { | ||
if let url = navigationAction.request.URL, callback = self.tryIntercept { | ||
if callback(url: url) { | ||
self.dismiss(true) | ||
return decisionHandler(.Cancel) | ||
} | ||
} | ||
return decisionHandler(.Allow) | ||
} | ||
|
||
public func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) { | ||
indicator.stopAnimating() | ||
indicator.removeFromSuperview() | ||
} | ||
|
||
public var startURL: NSURL? { | ||
didSet(oldURL) { | ||
if nil != startURL && nil == oldURL && isViewLoaded() { | ||
loadURL(startURL!) | ||
} | ||
} | ||
} | ||
|
||
public func loadURL(url: NSURL) { | ||
webView.loadRequest(NSURLRequest(URL: url)) | ||
} | ||
|
||
func showHideBackButton(show: Bool) { | ||
navigationItem.leftBarButtonItem = show ? UIBarButtonItem(barButtonSystemItem: .Rewind, target: self, action: #selector(DropboxConnectController.goBack(_:))) : nil | ||
} | ||
|
||
func goBack(sender: AnyObject?) { | ||
webView.goBack() | ||
} | ||
|
||
func cancel(sender: AnyObject?) { | ||
dismiss(true, animated: (sender != nil)) | ||
|
||
self.cancelHandler() | ||
} | ||
|
||
func dismiss(animated: Bool) { | ||
dismiss(false, animated: animated) | ||
} | ||
|
||
func dismiss(asCancel: Bool, animated: Bool) { | ||
webView.stopLoading() | ||
|
||
self.onWillDismiss?(didCancel: asCancel) | ||
presentingViewController?.dismissViewControllerAnimated(animated, completion: nil) | ||
} | ||
} |
Oops, something went wrong.