Lenguaje "Objective C"

Enviar mensajes – REST API – JSON

[code]
            
#import 

NSDictionary *headers = @{ @"Content-Type": @"application/json",
   @"Cache-Control": @"no-cache" };
NSDictionary *parameters = @{ @"message": @"Text of the SMS message",
    @"tpoa": @"Sender",
    @"recipient": @[ @{ @"msisdn": @"12015550123" }, @{ @"msisdn": @"447400123456" }, @{ @"msisdn": @"5212221234567" } ] };

NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.labsmobile.com/json/send"]
       cachePolicy:NSURLRequestUseProtocolCachePolicy
   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSString *authStr = [NSString stringWithFormat:@"%@:%@", [self myusername], [self mypassword]];
NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodingWithLineLength:80]];
[request setValue:authValue forHTTPHeaderField:@"Authorization"];

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;
            NSLog(@"%@", httpResponse);
        }
    }];
[dataTask resume];
[/code]

Consulta de créditos – REST API – JSON

[code]
#import 

NSDictionary *headers = @{ @"Cache-Control": @"no-cache" };

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.labsmobile.com/json/balance"]
       cachePolicy:NSURLRequestUseProtocolCachePolicy
   timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
[request setAllHTTPHeaderFields:headers];

NSString *authStr = [NSString stringWithFormat:@"%@:%@", [self myusername], [self mypassword]];
NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodingWithLineLength:80]];
[request setValue:authValue forHTTPHeaderField:@"Authorization"];

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;
          NSLog(@"%@", httpResponse);
      }
  }];
[dataTask resume];
[/code]

Enviar mensajes – HTTP/GET

[code]
NSURL *url = [NSURL URLWithString:@"http://api.labsmobile.com/get/send.php?username=[X]&password=[X]&msisdn=34609036253&sender=SENDER&message=This+is+the+message"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"ret=%@", ret);
[/code]

Consulta de créditos – HTTP/GET

[code]
NSURL *url = [NSURL URLWithString:@"http://api.labsmobile.com/get/balance.php?username=[X]&password=[X]"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"ret=%@", ret);
[/code]

Llámanos