Skip to content

Commit

Permalink
resolve warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nghialv committed May 24, 2015
1 parent 9f7b064 commit 218515d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Net.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Net"
s.version = "0.1"
s.version = "0.2.1"
s.summary = "Http Request wrapper written in Swift"
s.homepage = "https://github.com/nghialv"
s.screenshots = "https://camo.githubusercontent.com/18ae3452d66a0b8ad14ee6c897814044c79cec98/68747470733a2f2f646c2e64726f70626f7875736572636f6e74656e742e636f6d2f752f383535363634362f73637265656e73686f74322e706e67"
Expand All @@ -10,8 +10,8 @@ Pod::Spec.new do |s|
s.social_media_url = "https://twitter.com/nghialv2607"

s.platform = :ios
s.ios.deployment_target = "7.0"
s.source = { :git => "https://github.com/nghialv/Net.git", :tag => "0.1" }
s.ios.deployment_target = "8.0"
s.source = { :git => "https://github.com/nghialv/Net.git", :tag => "0.2.1" }

s.source_files = "Net/*"
s.requires_arc = true
Expand Down
24 changes: 17 additions & 7 deletions Net/Net.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import UIKit

// TODO: authentication
// TODO: cache
Expand Down Expand Up @@ -81,8 +82,17 @@ class Net : NSObject, NSURLSessionDataDelegate, NSURLSessionDownloadDelegate, NS
func setupSession(backgroundIdentifier: String? = nil) {
if backgroundIdentifier != nil {
if backgroundSession == nil {
//backgroundSessionConfig = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(backgroundIdentifier!)
backgroundSessionConfig = NSURLSessionConfiguration.backgroundSessionConfiguration(backgroundIdentifier!)

func systemVersionGreaterThanOrEqualTo(version: String) -> Bool {
let osVersion = UIDevice.currentDevice().systemVersion
return osVersion.compare(version, options: NSStringCompareOptions.NumericSearch) != NSComparisonResult.OrderedAscending
}

if systemVersionGreaterThanOrEqualTo("8.0") {
backgroundSessionConfig = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(backgroundIdentifier!)
} else {
backgroundSessionConfig = NSURLSessionConfiguration.backgroundSessionConfiguration(backgroundIdentifier!)
}
backgroundSessionConfig!.HTTPMaximumConnectionsPerHost = HTTPMaximumconnectionsPerHost

backgroundSession = NSURLSession(configuration: backgroundSessionConfig, delegate: self, delegateQueue: nil)
Expand Down Expand Up @@ -113,7 +123,7 @@ class Net : NSObject, NSURLSessionDataDelegate, NSURLSessionDownloadDelegate, NS

func GET(# absoluteUrl: String, params: NSDictionary?, successHandler: SuccessHandler, failureHandler: FailureHandler)
-> NSURLSessionTask {
return httpRequest(.GET, url: absoluteUrl, params: params, successHandler: successHandler, failureHandler: failureHandler, isAbsoluteUrl: true)
return httpRequest(.GET, url: absoluteUrl, params: params, isAbsoluteUrl: true, successHandler: successHandler, failureHandler: failureHandler)
}

// POST
Expand All @@ -124,7 +134,7 @@ class Net : NSObject, NSURLSessionDataDelegate, NSURLSessionDownloadDelegate, NS

func POST(# absoluteUrl: String, params: NSDictionary?, successHandler: SuccessHandler, failureHandler: FailureHandler)
-> NSURLSessionTask {
return httpRequest(.POST, url: absoluteUrl, params: params, successHandler: successHandler, failureHandler: failureHandler, isAbsoluteUrl: true)
return httpRequest(.POST, url: absoluteUrl, params: params, isAbsoluteUrl: true, successHandler: successHandler, failureHandler: failureHandler)
}

// PUT
Expand All @@ -135,7 +145,7 @@ class Net : NSObject, NSURLSessionDataDelegate, NSURLSessionDownloadDelegate, NS

func PUT(# absoluteUrl: String, params: NSDictionary?, successHandler: SuccessHandler, failureHandler: FailureHandler)
-> NSURLSessionTask {
return httpRequest(.PUT, url: absoluteUrl, params: params, successHandler: successHandler, failureHandler: failureHandler, isAbsoluteUrl: true)
return httpRequest(.PUT, url: absoluteUrl, params: params, isAbsoluteUrl: true, successHandler: successHandler, failureHandler: failureHandler)
}

// DELETE
Expand All @@ -145,7 +155,7 @@ class Net : NSObject, NSURLSessionDataDelegate, NSURLSessionDownloadDelegate, NS
}

func DELETE(# absoluteUrl: String, params: NSDictionary?, successHandler: SuccessHandler, failureHandler: FailureHandler) -> NSURLSessionTask {
return httpRequest(.DELETE, url: absoluteUrl, params: params, successHandler: successHandler, failureHandler: failureHandler, isAbsoluteUrl: true)
return httpRequest(.DELETE, url: absoluteUrl, params: params, isAbsoluteUrl: true, successHandler: successHandler, failureHandler: failureHandler)
}

// DOWNLOAD
Expand Down Expand Up @@ -296,7 +306,7 @@ class Net : NSObject, NSURLSessionDataDelegate, NSURLSessionDownloadDelegate, NS
*
* @return request instance
*/
private func httpRequest(method: HttpMethod, url: String, params: NSDictionary?, successHandler: SuccessHandler, failureHandler: FailureHandler, isAbsoluteUrl: Bool = false) -> NSURLSessionTask {
private func httpRequest(method: HttpMethod, url: String, params: NSDictionary?, isAbsoluteUrl: Bool = false, successHandler: SuccessHandler, failureHandler: FailureHandler) -> NSURLSessionTask {
let urlString = isAbsoluteUrl ? url : "\(baseUrl.absoluteString!)\(url)"
NSLog(urlString)

Expand Down

0 comments on commit 218515d

Please sign in to comment.