dijous, 15 de maig del 2014

Concurso de apps InnovaApps+




El banco BBVA en colaboración con Google acaba de lanzar el concurso InnovaApps  (http://www.bbvaopen4u.com/innovaapps/es) 

Si alguien tiene una aplicación terminada puede presentarla al concurso. La única condición es que se utilizen API's públicas de Google (por ejemplo el API Google Places).

Es una iniciativa conjunta de BBVA y Google, cuyo objetivo es el fomento del espíritu innovador en las soluciones de productividad accesibles para todas las empresas, especialmente la comunidad de pymes y startups.

Las aplicaciones que se desarrollen y presenten a InnovaApps+ deben estar bajo licencia Open Source (basado en el modelo de licencia Apache, versión 2.0). 

divendres, 2 de maig del 2014

Objective-C strings




As you know a common way to create strings is using the literal @"Some String" syntax, for instance:

Why is the reason of the @ sign in front of "Porsche"?
Objective-C is like two worlds in one. You can write, even in the same program, Objective-C and C code. 
In C language you can write a String literal this way:
char *amessage = "This is a string literal."; 
For this reason when you write a NSString literal you have to put the @ sign before the string. It's the way to say to the compiler that it is a NSString and not a C language string.
  
Of course, when writing iOS programs it is better to use NSStrings. C-language strings don't have support for Unicode, so you can't use accents or other punctuations signs.

dijous, 1 de maig del 2014

When it is advisable to use NSDecimalNumber instead of double?


Yesterday, a friend shared with me a problem using double. He was writing a Calculator app,  and he run into this incorrect result:
123456789123456.78 * 1 = 123456789123456.8


Here is why.
NSExpression uses internally the C-based primitive double. Your example can be written as:
double a = 123456789123456.78;
double b = 1.0;
NSLog (@"Result  %@ ", [NSNumber numberWithDouble: a*b]); // 123456789123456.8 
Why the result is 123456789123456.8 instead of 123456789123456.78? The primitive type double uses the IEEE-754 double precision format (http://en.wikipedia.org/wiki/Double-precision_floating-point_format), also known as Bynary64 because uses 64 bits to store the number. Storing a decimal number in a binary format has a number of disadvantages. There is a inherent rounding error that depends of the magnitude of the number.
Between 2 ^52=4,503,599,627,370,496 and 2^53=9,007,199,254,740,992 the representable numbers are exactly the integers. So:
double a = 4503599627370496.6;
double b = 1.0;
NSLog (@"Result  %@ ", [NSNumber numberWithDouble: a*b]); //4503599627370497 
Between 2^53 =9007199254740993to 2^54, everything is multiplied by 2, so the representable numbers are the even ones. So:
double a = 9007199254740993;
double b = 1.0;
NSLog (@"Result  %@ ", [NSNumber numberWithDouble: a*b]); //9007199254740992 
Conversely, for the previous range from 2^51 to 2^52, the spacing is 0.5, etc.
In your case, the number 123456789123456 is in the interval 2^46 - 2^47 and the rounding error is 1 / 64 = 0.015625.
With 64 bits you can work only with a maximum of 15-17 decimal digits, and you'll get rounding errors in all the range.
The solution? You can use NSDecimalNumber that uses decimal arithmetic( Java has BigDecimal )
NSDecimalNumber *decimaNumber = [NSDecimalNumber decimalNumberWithString:  @"4503599627370496.11"];
NSDecimalNumber *decimaNumber2 = [NSDecimalNumber decimalNumberWithString:  @"1"];
NSLog(@"    %@",[decimaNumber decimalNumberByMultiplyingBy:decimaNumber2]);  //4503599627370496.11

dijous, 10 d’abril del 2014

First Hop app released !



First Hop Free app has been approved in the AppStore. By the way the review process took 6 days. Now you can download for free here.

Use the free FirstHop app to easily get access to important networking information about your iOS device. The main information panel displays the public IP address, the location of your ISP, and the name and network of your ISP.

diumenge, 23 de febrer del 2014

Understanding Apple's SSL/TLS bug


Yesterday, an entry about a serious Apple's bug reached the top of Hacker News The  bug was related with SSL/TTL connections.

Any time you have a bug that affects SSL/TLS you should pay close attention. As a quick refresher, SSL/TLS refers to encryption protocols that are widely and commonly used to encrypt the transmission of sensitive data. Any bug affecting SSL/TLS has the ability to undermine many, if not all, of the secure transmissions made from your devices.

Fortunately the code is open sourced, and the culprit was quickly spotted, here is the Apple bug:



static OSStatus
SSLVerifySignedServerKeyExchange(SSLContext *ctx, bool isRsa, SSLBuffer signedParams,
                                 uint8_t *signature, UInt16 signatureLen)
{
 OSStatus        err;
 ...

 if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0)
  goto fail;
 if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
  goto fail;
  goto fail;
 if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0)
  goto fail;
 ...

fail:
 SSLFreeBuffer(&signedHashes);
 SSLFreeBuffer(&hashCtx);
 return err;
}

Wow, note the two goto fail lines in a row.The first one is correctly bound to the if statement but the second, despite the indentation, isn't conditional at all. The code will always jump to the end from that second goto, err will contain a successful value because the SHA1 update operation was successful and so the signature verification will never fail.

UPDATE 1. More information here 

UPDATE 2. Apple promises fix 'very soon' for Macs with failed encryption

divendres, 21 de febrer del 2014

Checking network availability


In order to check the network availability of your device you can use the Apple Reachability class.  You can even hook up to be notified of network status changes through the ReachabilityCallback. 

But if you prefer a  a quick and dirty solution use this:
Write the following C code and save on a file named Goodies.h:


#include<unistd.h>
#include<netdb.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/socket.h>


extern bool is_NetworkAvailable();

The matching implementation is Goodies.m


#include <stdio.h>
#include "Goodies.h"


bool is_NetworkAvailable()
{
    char *hostname;
    hostname = "google.com";
    
    struct addrinfo *res = NULL;
    int s = getaddrinfo(hostname, "http", NULL, &res);
    bool network_ok = (s == 0 && res != NULL);
    freeaddrinfo(res);
    if (network_ok ) {
        return 1;
    }
    else {
        return 0;
    }
    

}

And that's all. Now import Goodies.h an you can use the function is_NetworkAvailable() everywhre.
 



boolean _isNetworkAvailable = is_NetworkAvailable();

if (_isNetworkAvailable) {

          // Network related tasks

} else {

       UIAlertView *message = [[UIAlertView alloc]                                initWithTitle:@"Alert"
                 message:@"Nointernet connectivity." delegate:nil
                 cancelButtonTitle:@"OK"
                 otherButtonTitles:nil];

      [message show];

}