-5

Hi all am developing a app using swift2 am having api key in Json format i can able to work with that and it provides some data such as success:1,error:0 if i get the value success 1 means i want to send the entered data or saved data to a server(api key).How to do that??

Thanks in advance

antonyraja
  • 13
  • 7
  • do you know about afnetwoking ? – KKRocks Nov 15 '16 at 06:16
  • NO dude....can you refer something?? – antonyraja Nov 15 '16 at 06:31
  • @antonyraja I dont even know why you think more pods = more battery consumtion...really man? I think you should learn the basic of coding first before trying to dev anything, else it wont work well and possibly of many bugs – Tj3n Nov 15 '16 at 07:52
  • in my app am updating current location for every 1 minutes even app in background active...so already it consumes more memory thats the reason i dont want to add any additional frameworks and pods – antonyraja Nov 15 '16 at 08:15

1 Answers1

0

you can send data to server by using Alamofire API. It's documention and implemention all the stuff are mentioned in the following link.

https://github.com/Alamofire/Alamofire

Just install it using Pods and it's very easy to implement.

create Network Class and create following function inside it.

   func get_Request(currentView : UIViewController,action : NSString,completionHandler: (NSDictionary -> Void)) {
    print("Url==>>>",mainURl + (action as String))

    Alamofire.request(.GET,mainURl + (action as String), parameters: nil)
        .responseJSON { response in

            if let JSON = response.result.value {
                completionHandler(JSON as! NSDictionary)
            }
            else{
                printf(response.result.error?.localizedDescription)
            }
        }
}

Other class

viewDidLoad{
    NetworkClass.get_Request(self,action: "yourServiceName/" + (yourParameters as String), completionHandler: self.resultHandler)
}
func resultHandler(result : NSDictionary) -> Void {

    printf("result is -->>",result)

}
Sumit Jangra
  • 651
  • 5
  • 16
  • I dont want to use cocoapod because am already using two pods..if i again add the cocoapod means my app will drain battery...so is there any other way to do???? – antonyraja Nov 15 '16 at 06:26
  • @antonyraja: Who said using more than one cocoapod will drain battery? – Poles Nov 15 '16 at 06:32
  • Pods are just store files from source to your project instead you manually import them.Pods does not affect your battery consumptions. – Sumit Jangra Nov 15 '16 at 06:32
  • Pods are best way rather then manually .Because when any update come's in the library then you need to remove old files and add new file into project but using pods you can easily update them. – Sumit Jangra Nov 15 '16 at 06:39
  • but if you want to do it then just follow this link http://stackoverflow.com/questions/31706589/how-to-add-alamofire-to-xcode-project-swift – Sumit Jangra Nov 15 '16 at 06:40
  • using this alomofire how to send the data – antonyraja Nov 15 '16 at 06:45
  • Have u Read the alamofire documention in the link of gitHub i mentions.you can get solution how to send data. Try it once otherwise i give you the solution – Sumit Jangra Nov 15 '16 at 06:52
  • source 'https://github.com/CocoaPods/Specs.git' platform :ios, '9.0' use_frameworks! pod 'Alamofire', '3.2.1' – Sumit Jangra Nov 15 '16 at 06:58
  • i have updated my pods(Alamofire)....now am getting a value in textfield...i want to send that data to server(i.e...api)...how to send???? @SumitDhariwal – antonyraja Nov 15 '16 at 09:26
  • i have updated my pods(Alamofire)....now am getting a value in textfield...i want to send that data to server(i.e...api)...how to send???? @SumitDhariwal – antonyraja Nov 15 '16 at 10:11
  • it helps to print the parameter and fetch result as SUCCESS or FAILURE but i dont know where to work with this coding that is public enum Result { case success(value) case failure(Error)} – antonyraja Nov 15 '16 at 11:24
  • Because am implementing in button action – antonyraja Nov 15 '16 at 11:24
  • am having two text field change password and confirm change password and am having one button action...inside that action i have to perform but your updated answer is confusing where to use it..can you explain little bit more???? – antonyraja Nov 15 '16 at 12:57
  • don't be confuse ,you just need to create a singleton Network class and a function which use to call api's ,in button action you just call api method of network class and pass your parameters,action,current View so that you can show indicator on current view and also a completion handler which can receive the result after successfull hit of api. – Sumit Jangra Nov 15 '16 at 13:00
  • am not comfortable with ios development man....can you refer any example or stackoverflow answers regarding my solution....thank you..@SumitDhariwal – antonyraja Nov 15 '16 at 13:04