Posts

Showing posts with the label call API

How to Call API in swift using Alamofire

if you first time call API in your App than add it in you Info.plist <key> NSAppTransportSecurity </key> <dict> <key> NSAllowsArbitraryLoads </key> <true/> </dict> than install pod 'Alamofire' and import it like: Code : import Alamofire func callAPINoParameters()     {         let strURL =  yourURL                  Alamofire. request (strURL). responseJSON { (response) in             switch response. result {             case . success ( let JSON):                                  let response = JSON as ! NSDictionary                 print (response)                 break                              case . failure ( let error):                 print ( "Request failed with error: \ ( error )" )                 break             }         }     }     func callAPIWithParameters()     {         let strURL = yourURL    

Full AFNetwork tutorial in swift with code

-------------------------------- APIDemo-Bridging-Header.h ----------------------- #import <AFNetworking/AFNetworking.h> #import "WebServiceCallClass.h" ---------------------------------- WebServiceCallClass.h -------------------------- #import <Foundation/Foundation.h> @interface WebServiceCallClass : NSObject +(void)callWebServiceUsingGetMethodGetURL:(NSString *)strURL successBlock:(void(^)(id responseObject))sucess failureBlock:(void(^)(id errorResponse))fail; +(void)callWebServiceUsingPostMethodPostURL:(NSString *)strURL withParamiterDicrionary : (NSDictionary *)paramiterDict successPostBlock:(void(^)(id responseObject))sucess failurePostBlock:(void(^)(id errorResponse))fail; @end ---------------------------------- WebServiceCallClass.m ---------------------------------- #import "WebServiceCallClass.h" #import <AFNetworking/AFNetworking.h> @implementation WebServiceCallClass +(void)callWebServiceUsingGetMethodGetURL:(NSString *)strURL successB

How to Call API using AFNetwork in Swift

 Install Pod file on your Project open this link for install pod file : install pod in mac Write this code on your Project and Used it.  import UIKit class AppHandler: NSObject { class var sharedInstance: AppHandler { struct Static { static var onceToken: Int = 0 static var instance = AppHandler() } return Static.instance } let manager = AFHTTPRequestOperationManager(); func checkForNewUpdates(){ let parameters = NSMutableDictionary(); parameters.setObject("1", forKey: "U_ID" as NSCopying); AppHandler.sharedInstance.manager.post( "Your URL Type HERE", parameters: parameters, success: { (operation,responseObject) in Z.log("JSON: " + (responseObject as AnyObject).description) if let errorResponse = (responseObject as AnyObject).value(forKeyPath: &quo