Share their own application examples of accessing SMS verification code in the development of tool projects , The way is :Objective-C - NSURLSession, Take the SMS interface of each big cloud market as an example , Examples are as follows :
`
import <Foundation/Foundation.h>
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://vip.veesing.com/smsApi/verifyCode"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSDictionary *headers = @{
@"Content-Type": @"application/x-www-form-urlencoded;charset=utf-8"
};
[request setAllHTTPHeaderFields:headers];
NSMutableData postData = [[NSMutableData alloc] initWithData:[@"appId=41KYR0EB*" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&appKey=IIWCKKSR7NOQ**" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&phone=1561894**" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&templateId=1043" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&variables=1234" dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postData];
[request setHTTPMethod:@"POST"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData data, NSURLResponse response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSError *parseError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSLog(@"%@",responseDictionary);
dispatch_semaphore_signal(sema);
}
}];
[dataTask resume];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
`
It is almost a must to add SMS verification code to the project , Even SMS captcha , It also needs more protection !
Objective-C - NSURLSession.m And document description download