NRConnection: lets use the network layer in the simplest way. Send/Get parameters,images and videos from/to server in a simplest way. Well there are various network classes available for open source, but most of them missing the simplicity . NRConnection allow developers to post parameters, images and videos in a simplest way. Just a single method for video and images which needs the array of images and videos and NRConnection sends it to the server in a most elegant way with the use of Alamofire. You can get the success/failure with the help of NRCompletionHandler.
To run the example project, clone the repo, and run pod install
from the Example directory first.
Xcode 7+ , Swift 2 , iOS 9 and above
NRConnection is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "NRConnection"
BASE_URL = "https://jsonplaceholder.typicode.com/" // change baseurl with your server url.
NRConnection.callServiceWithName(.GET, serviceName: "posts", parameters: [:]) { (response, result) in
if response.successful() { // do your work with result if response is successful
}
}
BASE_URL = "" // change baseurl with your server url.
let params = ["userId": "5", "userName": "Naveen Rana"]
NRConnection.callServiceWithName(.POST, serviceName: "posts", parameters: params) { (response, result) in
if response.successful() { // do your work with result if response is successful
}
}
func sendImages() {
let imagesArray = [UIImage(named: "test1")!,UIImage(named: "test2")!]
let params = ["userId": "5", "userName": "Naveen Rana"]
NRConnection.callServiceWithImagesVideosArray(imagesArray: imagesArray, parameters: params, serviceName: "PostImages") { (response, result) in
if response.successful() {
print("images post successfully")
}
}
}
func sendVideos() {
let videosArray = [NSData(contentsOfURL: NSURL(string: "videoUrl")!)!]
let params = ["userId": "5", "userName": "Naveen Rana"]
NRConnection.callServiceWithImagesVideosArray(videoArray: videosArray, parameters: params, serviceName: "PostImages") { (response, result) in
if response.successful() {
print("images post successfully")
}
}
}
func onlyUrl() {
NRConnection.callServiceWithURL(NSURL(string: "https://github.com/naveenrana1309/NRConnection")!) { (response, result) in
if response.successful() {
print("url hit successfully")
}
}
}
- BASE_URL , you have to change this url with your server url , this parameter is public variable so you can change this in your configuration file.
- Please check your encoding if its not working , please be sure your backend developer use same encoding.
- You can change the encoding parameter according to your requirement also.
Contributions are always welcome! (:
- Fork it ( http://github.com/naveenrana1309/NRConnection/fork )
- Create your feature branch ('git checkout -b my-new-feature')
- Commit your changes ('git commit -am 'Add some feature')
- Push to the branch ('git push origin my-new-feature')
- Create new Pull Request
Xcode 7+ , Swift 2 , iOS 9 and above
Naveen Rana. See Profile
Email: naveenrana1309@gmail.com.
Check out Facebook Page for detail.
NRConnection is available under the MIT license. See the LICENSE file for more info.