HTTP SEND SMS API Using iOS
Code:
//Create Objects
NSMutableData * responseData;
NSURLConnection * connection;
// In your viewDidLoad method add this lines
-(void)viewDidLoad
{
[super viewDidLoad];
//Your authentication key
NSString * authkey = @"YourAuthKey";
//Multiple mobiles numbers separated by comma
NSString * mobiles = @"9999999";
//Sender ID,While using route4 sender id should be 6 characters long.
NSString * senderId = @"102234";
//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:@"http://api.msg91.com/api/sendhttp.php?authkey=%@&mobiles=%@&message=%@&sender=%@&route=%@", authkey, mobiles, message, senderId, 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];
}