NetworkHelper

public class NetworkHelper : NSObject
extension NetworkHelper: URLSessionDataDelegate
extension NetworkHelper: URLSessionDownloadDelegate
extension NetworkHelper: URLSessionTaskDelegate

NetowrkHelper is used to perform basic level internet connection.

Author

Adamas

Version

1.9.2

Date

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

    urlString

    The url of the destination.

    header

    The header of the post.

    body

    The content of the request.

    type

    The type of the request.

    isUploadTask

    Whether 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

    urlString

    The url of the destination.

    header

    The header of the post.

    formData

    The form data to be posted.

    isUploadTask

    Whether 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

    urlString

    The url of the destination.

    header

    The header of the get.

    isDownloadTask

    Whether 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

    urlString

    The address of the destination.

    header

    The 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?)