【问题标题】:SMS online sending service短信在线发送服务
【发布时间】:2014-05-09 20:59:21
【问题描述】:

我正在寻找可以在我的 iOS 应用程序中使用的在线短信发送服务。 我的目标是向用户提供的电话号码发送验证码。 在 Android 中这没什么大不了的,因为我可以通过编程方式发送短信,但在 iOS 中 我不能。有什么建议吗?

【问题讨论】:

    标签: ios service sms


    【解决方案1】:

    在我们的应用程序中,我们使用http://www.twilio.com/ 通过 iPhone 上的服务发送短信,这非常棒。

    对于发送 SMS,您甚至不需要下载他们的 SDK 并将其放入您的项目中。它基本上归结为一个 HTTP POST 命令,您可以在其中向 SMS 提供电话号码、消息正文和您的 API 密钥+秘密。

    为了方便您通过 Twillio 发送短信,以下是一个示例:

    - (void)twilloSendSMS:(NSString *)message withQueue:(NSOperationQueue *)queue
               andSID:(NSString *)SID andSecret:(NSString *)secret
        andFromNumber:(NSString *)from andToNumber:(NSString *)to {
        NSLog(@"Sending request.");
    
        // Build request
        NSString *urlString = [NSString stringWithFormat:@"https://%@:%@@api.twilio.com/2010-04-01/Accounts/%@/SMS/Messages", SID, secret, SID];
    
        NSURL *url = [NSURL URLWithString:urlString];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:url];
        [request setHTTPMethod:@"POST"];
    
        // Set up the body
        NSString *bodyString = [NSString stringWithFormat:@"From=%@&To=%@&Body=%@", from, to, message];
        NSData *data = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
        [request setHTTPBody:data];
    
        [NSURLConnection
         sendAsynchronousRequest:request
         queue:queue
         completionHandler:^(NSURLResponse *response,
                             NSData *data,
                             NSError *error)
         {
             NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
             if ([data length] >0 && error == nil && ([httpResponse statusCode] == 200 ||     [httpResponse statusCode] == 201))
             {
    
                 NSString *receivedString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                 NSLog(@"Request sent. %@", receivedString);
    
         }
         else {
                 NSString *receivedString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                 NSLog(@"Request sent. %@", receivedString);
                 NSLog(@"Error: %@", error);
         }
     }];
    }
    

    【讨论】:

    • 然后我就简单的调用你上面提供的函数?
    • 是的,您基本上只需要注册该服务,您就可以使用我提供的功能。一开始你会得到一个测试号码(这是你的号码),你可以免费发送给它,只是为了测试服务。因此,您可以尝试向该电话号码发送一些“hello world”消息正文,然后查看它是否正常工作。
    • 但是当我想发送到各种号码时,需要花费吗?
    • 是的,你可以在这里查看他们的价格范围:twilio.com/sms/pricing
    • 好吧,我猜没有免费服务?
    猜你喜欢
    • 1970-01-01
    • 2018-04-16
    • 2017-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-06
    • 2023-03-06
    • 1970-01-01
    相关资源
    最近更新 更多