Welcome to the documentation for YTKNetwork!
Overview
YTKNetwork is a lightweight and high-performance iOS network library. It’s built on top of AFNetworking but provides a simplified and convenient API for making HTTP requests. With YTKNetwork, you can easily manage the request life cycle, handle network errors, and easily integrate with other libraries or frameworks.
Installation
To install YTKNetwork, you have several options:
- CocoaPods: Add the following line to your Podfile:
pod 'YTKNetwork'
- Carthage: Add the following line to your Cartfile:
github "yuantiku/YTKNetwork"
- Manually: Download the latest release from the GitHub repository and add the necessary files to your project.
Getting Started
Once you have installed YTKNetwork, follow these steps to start using it:
- Create a new subclass of
YTKRequest
. - Override the
requestUrl
method to return the URL for your request. - Override the
requestMethod
method to specify the HTTP method for your request. - Implement the
requestArgument
method to provide any additional request parameters. - Optionally, override other methods to customize the request behavior.
- Send the request using the
start
method.
Here’s an example of a subclassed request:
import YTKNetwork
class MyRequest: YTKRequest {
override func requestUrl() -> String {
return "https://api.example.com/path"
}
override func requestMethod() -> YTKRequestMethod {
return .get
}
override func requestArgument() -> Any? {
return ["param1": "value1", "param2": "value2"]
}
}
Make sure to create a shared instance of the request object and use it to send requests throughout your app.
Advanced Usage
Besides the basic usage outlined above, YTKNetwork offers several advanced features:
- Request Callbacks: You can implement various callback methods in your request subclass to handle the request’s life cycle, parse response data, and handle error scenarios.
- Request Groups: YTKNetwork allows you to create request groups to synchronize multiple requests and handle dependency between them.
- Serializer: You can choose different serializers for handling request and response data including JSON, HTTP, or custom ones.
- Reachability: YTKNetwork provides a built-in reachability component to monitor network connection status.
- File Upload: You can upload files using YTKNetwork and easily monitor the upload progress.
- SSL Pinning: YTKNetwork supports SSL pinning to enhance network security.
FAQ
Here are some frequently asked questions about YTKNetwork:
- Q: Can I use YTKNetwork with Swift?
A: Yes, YTKNetwork is fully compatible with both Objective-C and Swift projects. - Q: How can I handle network errors?
A: You can implement therequestFailedFilter
method in your request subclass to customize the error handling logic. - Q: Can I cancel a request?
A: Yes, you can call thecancel
method on a request object to cancel an ongoing request. You can also cancel a request group to cancel all requests within that group.
Community and Support
If you need help or have any inquiries, you can reach out to the YTKNetwork community for support:
- Join the GitHub repository and submit any issues or feature requests.
- Ask questions and share ideas in the Discussions section.
- Join the Gitter chat room to interact with other users and maintainers.