Posted By

Broadnet on 08/02/17


Tagged

phone code api sample sms messaging ios


Versions (?)

Example of iOS Phone Sample SMS Code - Messaging API


 / Published in: iPhone
 

URL: https://www.broadnet.me/developer-tools/sms-sample-code/ios-sample-code-sms.html

The following example of iOS Phone sample SMS code employs user-friendly object, with a basis on the HTTP API.

  1. //IOS SMS API integration code
  2.  
  3. //Create Objects
  4. NSMutableData * responseData;
  5. NSURLConnection * connection;
  6.  
  7. // In your viewDidLoad method add this lines
  8. -(void)viewDidLoad
  9. {
  10. [super viewDidLoad];
  11. //Your application url
  12. NSString * ApiUrl = @"ApiUrl";
  13. //Multiple mobiles numbers separated by comma
  14.  
  15. NSString * user = @"uname";
  16. NSString * pass = @"******";
  17.  
  18. NSString * mobiles = @"9999999";
  19. //Sender ID,While using route4 sender id should be 6 characters long.
  20. NSString * sid = @"102234";
  21. //Your message to send, Add URL encoding here.
  22. NSString * message = @"Test message";
  23.  
  24. // Prepare your url to send sms with this parameters.
  25. NSString * url = [[NSString stringWithFormat:@"https://broadnet.me/api/xxxxx.php?user=%@&pass=%@&mobiles=%@&message=%@&sid=%@", user, pass, mobiles, message, sid] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  26. NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
  27. connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  28. }
  29.  
  30. // implement URLConnection Delegate Methods as follow
  31. -(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
  32. {
  33. //Get response data
  34. responseData = [NSMutableData data];
  35. }
  36.  
  37. -(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  38. {
  39. [responseData appendData:data];
  40. }
  41.  
  42. -(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
  43. {
  44. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"message:error.localizedDescription delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
  45. [alert show];
  46. }
  47.  
  48. -(void) connectionDidFinishLoading:(NSURLConnection *)connection
  49. {
  50. // Get response data in NSString.
  51. NSString * responceStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  52. }

Report this snippet  

You need to login to post a comment.