iOS手机示例短信代码-短信API

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS手机示例短信代码-短信API相关的知识,希望对你有一定的参考价值。

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. }

以上是关于iOS手机示例短信代码-短信API的主要内容,如果未能解决你的问题,请参考以下文章

验证码短信 API 接入指南:Java 语言示例代码

企业信使短信接口API代码示例

Ruby国际短信API接口demo

无法在片段内查看接收短信

VB6示例短信代码-消息API

向手机发送短信的python源代码,该怎么解决