我想解析twilio网址的数据,这将用于SMS verification
请帮助将swift转换为以下代码的目标:
@IBAction func pressedSend(sender: AnyObject) {
let code = arc4random_uniform(8999) + 1000
var data = [
"To" : textTo.text as String,
"From" : "<replace with your Twilio local number>",
"Body" : String(code) as String
]
var swiftRequest = SwiftRequest()
swiftRequest.post("https://api.twilio.com/2010-04-01/Accounts/ACc4e304c952c972c26699b927422e668953/Messages",
auth: ["username" : "ACc4e304c952c972c26699b927422e668953", "password" : "5ab5312824b1d057dea249668e2c4189"],
data: data,
callback: {err, response, body in
if err == nil {
println("Success: (response)")
} else {
println("Error: (err)")
}
})
}
感谢您的帮助
答案 0 :(得分:2)
我认为它应该是这样的。不确定swiftRequest
所以我假设你的网络请求类。
-(IBAction)pressedSend:(id) sender{
NSInteger code = arc4random_uniform(8999)+1000;
NSDictionary *data = @{@"To":textTo.text, // guessing this is a label?
@"From":"<replace with your Twilio local number>",
@"Body":[NSString stringWithFormat:@"%d",code]
};
SwiftRequest *swiftRequest = [SwiftRequest new];
[swiftRequest Post:@"https://api.twilio.com/2010-04-01/Accounts/ACc4e304c952c972c26699b927422e668953/Messages"
auth:@{@"username" : @"ACc4e304c952c972c26699b927422e668953",
@"password" : @"5ab5312824b1d057dea249668e2c4189"}
callback:(NSerror *error, id response){
if(error != nil){
// has error
}
else{
// has no error
}
}
}];
}//end method