2017-02-21 84 views
0

我已經購買了號碼,但我不能夠發送短信的 給人錯誤的請求400.By使用試驗次數,我能夠發送下面 短信我使用AFNewtorking的API或是否有任何其他的方法來發送短信消息購買數量

NSString *kTwilioSID = @" "; 
    NSString *kTwilioSecret = @" "; 
    NSString *kFromNumber = @"+ "; 

    NSString* nospacestring =[phno stringByReplacingOccurrencesOfString:@" " withString:@""]; 
    NSString *kToNumber = nospacestring; 
    NSString *kSMSMessage = @"Smart Child Info is a precautionary app designed to fight child abduction, exploitation, and maltreatment."; 

    // Build request 
    NSString *urlString = [NSString stringWithFormat:@"https://%@:%@@api.twilio.com/2010-04-01/Accounts/%@/SMS/Messages/", kTwilioSID, kTwilioSecret, kTwilioSID]; 

    NSString *Loginurl = urlString; 


    NSDictionary* 
    [email protected]{@"From":kFromNumber,@"To":kToNumber,@"Body":kSMSMessage}; 

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; 

    manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments]; 

    manager.responseSerializer = [AFHTTPResponseSerializer serializer]; 

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/plain",@"application/xml",nil]; 

    [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 

    [manager POST:Loginurl parameters:dic progress:nil success:^(NSURLSessionTask *task, id responseObject) { 


     NSLog(@"Response from server : %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]); 

     NSData * data = (NSData *)responseObject; 
     NSString* xmlData = [NSString stringWithCString:[data bytes] encoding:NSISOLatin1StringEncoding]; 
     NSLog(@"%@",xmlData); 

     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Success" message:@"Message has been sent" preferredStyle:UIAlertControllerStyleAlert]; 

     UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; 
     [alertController addAction:ok]; 

     [self presentViewController:alertController animated:YES completion:nil]; 

    } 
      failure:^(NSURLSessionTask *operation, NSError *error) 

    { 

     NSLog(@"Error: %@", error); 

     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Failed" message:@"Message not sent" preferredStyle:UIAlertControllerStyleAlert]; 

     UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; 
     [alertController addAction:ok]; 

     [self presentViewController:alertController animated:YES completion:nil]; 

    }]; 

回答

0

Twilio開發商傳道這裏呼籲 API,用於購買有效的數字。

首先,我們不建議您從iOS應用程序直接向API調用Twilio API。如果有人要解開你的應用程序,他們可以訪問你的帳戶SID和驗證令牌,然後用你的帳戶隨心所欲。

其次,您正在使用已棄用的SMS/Messages端點。相反,你應該使用更多最新的Messages endpoint

我建議你看看sending SMS messages with Twilio on iOS這篇博文。它涵蓋了如何設置服務器來發送消息,然後與該服務器進行交互。