Added code to check the return value from NSString.cStringUsingEncoding.