//IOS SMS API integration code

//Create Objects
NSMutableData * responseData;
NSURLConnection * connection;

// In your viewDidLoad method add this lines -(void)viewDidLoad { [super viewDidLoad]; //Your ApiKey key NSString * apikey = @"YourApikey"; //Approved sender id(6 characters string only). NSString * senderid = @"TESTIN"; //Message channel Promotional=1 or Transactional=2. NSString * channel = @"2"; //Default is 0 for normal message, Set 8 for unicode sms. NSString * DCS = @"0"; //Default is 0 for normal sms, Set 1 for immediate display. NSString * flashsms = @"0"; //Recipient mobile number (pass with comma seprated if need to send on more then one number). NSString * number = @"9999999"; //Your message to send, Add URL encoding here. NSString * message = @"Test message"; //define route NSString * route = @"default";
// Prepare your url to send sms with this parameters. NSString * url = [[NSString stringWithFormat:@"https://www.smsgatewayhub.com/api/mt/SendSMS?apikey=%@&senderid=%@&channel=%@&DCS=%@&flashsms=%@"number=%@"message=%@"route=%@", apikey, senderid, channel, DCS, flashsms , mobile , message , route] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; }
// implement URLConnection Delegate Methods as follow -(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { //Get response data responseData = [NSMutableData data]; }
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [responseData appendData:data]; }
-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; [alert show]; }
-(void) connectionDidFinishLoading:(NSURLConnection *)connection { // Get response data in NSString. NSString * responceStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; }