NetworkHelper
public class NetworkHelper : NSObject
extension NetworkHelper: URLSessionDataDelegate
extension NetworkHelper: URLSessionDownloadDelegate
extension NetworkHelper: URLSessionTaskDelegate
NetowrkHelper is used to perform basic level internet connection.
Version
1.9.2Date
28/03/2023-
The default helper.
Declaration
Swift
public static let standard: NetworkHelper? -
Whether the network is available or not. This method is referenced from http://stackoverflow.com/questions/39558868/check-internet-connection-ios-10
Declaration
Swift
public var isNetworkAvailable: Bool { get } -
The delegate of the Self.
Declaration
Swift
public weak var delegate: NetworkHelperDelegate? -
Initialize the object.
Declaration
Swift
public init(identifier: String = String(Date().timeIntervalSince1970), cache: URLCache = URLCache.shared) -
Send a asychoronous post request.
Declaration
Swift
public func postData(toURL urlString: String, with body: Data, as type: NetworkBodyType, with header: NetworkRequestHeader? = nil, asUploadTask isUploadTask: Bool = false) -> String?Parameters
urlStringThe url of the destination.
headerThe header of the post.
bodyThe content of the request.
typeThe type of the request.
isUploadTaskWhether the task should be run in the background or not.
Return Value
The identifier of the task.
-
Post a form to a specific url.
Declaration
Swift
public func postData(toURL urlString: String, with formData: FormData, with header: NetworkRequestHeader? = nil, asUploadTask isUploadTask: Bool = false) -> String?Parameters
urlStringThe url of the destination.
headerThe header of the post.
formDataThe form data to be posted.
isUploadTaskWhether the task should be run in the background or not.
Return Value
The identifier of the task.
-
Send a get request.
Declaration
Swift
public func getData(fromURL urlString: String, with header: NetworkRequestHeader? = nil, asDownloadTask isDownloadTask: Bool = false) -> String?Parameters
urlStringThe url of the destination.
headerThe header of the get.
isDownloadTaskWhether current task is a download task or not.
Return Value
The task identifier.
-
Send a delete request.
Declaration
Swift
public func deleteData(atURL urlString: String, with header: NetworkRequestHeader? = nil) -> String?Parameters
urlStringThe address of the destination.
headerThe header of the delete.
Return Value
The identifier of the new task.
-
Reset the internet, which will cancel all the current internet connections.
Declaration
Swift
public func reset() -
Clear all cache data.
Declaration
Swift
public func clearCache() -
Undocumented
Declaration
Swift
public func clearCache(forURL urlString: String) -
Undocumented
Declaration
Swift
public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) -
Undocumented
Declaration
Swift
public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) -
Undocumented
Declaration
Swift
public func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) -
Undocumented
Declaration
Swift
public func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) -
Undocumented
Declaration
Swift
public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?)
NetworkHelper Class Reference