Liste des appels Swisscom

(English version available here)

Ici en Suisse, mon opérateur téléphonique (Swisscom) a une option qui me permet de voir la liste des 20 derniers appels reçus ou manqués sur la page web de mon compte.

Ne désirant pas me connecter à cette page a chaque fois que je veux consulter cette liste afin de vérifier qui m’a appelé, j’ai écris quelques scripts qui récupèrent le contenu de cette page et l’affiche sur mon iPhone via une application iOS. Les noms sont récupérés depuis le carnet d’adresse et une notification est envoyée (via Prowl) quand un appel est reçu mais personne ne répond.

screen

Cette application iOS ne peut être distribuée en l’état sur l’AppStore car:

  • J’ai besoin des identifiants et mot de passe du compte Swisscom pour accéder à ces données et je n’aurai pas confiance dans un service qui me demanderait ces infos. Comme vous, je suppose.
  • La méthode utilisée pour récupérer la liste des appels n’est pas une méthode officielle et peut (comme cela est déjà arrivé) ne plus fonctionner si Swisscom change l’aspect de la page web.
  • L’application iOS peut rechercher le nom d’après un numéro inconnu via un appel à Local.ch (qui est plus ou moins l’annuaire suisse en ligne officiel). Bien sûr, il n’y a pas d’API officielle pour ce service et ils peuvent couper l’accès à tout moment. Soyez sympa et n’abusez pas de service.

J’ai mis le source à disposition sur GitHub: https://github.com/sburlot/phonecalls

Pour Swisscom

Si vous travaillez pour Swisscom, ou connaissez quelqu’un qui y travaille, demandez une méthode publique pour accéder à ces données, en proposant un login authentifié. Ca serait pratique et permettrait à cette app (et à d’autres!) d’être disponible pour le grand public.

Ou Swisscom pourrait ajouter cette fonctionnalité à leur application officielle,

Ou Swisscom pourrait m’embaucher pour implémenter cette fonctionnalité dans leur application. Je suis développeur freelance et disponible!

Quelques détails techniques

Sur le serveur, un script Perl va récupérer les données (via cron) du portail Swisscom et les enregistre dans une base MySQL (n’importe quelle base fonctionnerait).

L’application iOS appelle un script PHP sur le serveur: le serveur va récupérer les données de la base et renvoie un objet JSON.

Amusez-vous bien!

PS: bien sûr, je peux attendre d’être chez moi pour consulter les appels en absence sur mon téléphone, mais c’est moins geek et drôle. 😉

(Ceci est une version plus longue du post précédent en anglais)

Swisscom Phonecalls

(Version française disponible ici)

Here in Switzerland the major telco (Swisscom) has an option to let you see your last 20 answered and missed calls on your account webpage.

Not wanting to log in every time I want to check if I missed a call, I wrote some scripts and that fetches the content of my account web page and display them on an iOS app.

The names are fetched from the iPhone address book, and the iPhone receives a notification via Prowl when a call is missed.

screen

Or perhaps all this was an excuse to write some code during the holidays. Who knows.

I can’t make this app an official app because:

  • I need the Swisscom credentials to access the portal and I wouldn’t trust a stranger and give them access to my account. As you do.
  • The process of fetching the list of calls is not an officially approved method and may break (and did) when Swisscom changes the layout of the page.
  • The iOS app can also retrieve the owner of an unknown number via a call to the local.ch (more or less the official swiss white pages site). Of course, the API endpoint is not official nor public. Please be nice and don’t abuse this unofficial endpoint.

So I made the source available on GitHub: https://github.com/sburlot/phonecalls

For Swisscom

Oh, if you work for Swisscom, or know someone who does, ask for a method to fetch this data with a secure login option. That would be great, because I could make this app available via the AppStore.

Or Swisscom could add this feature to their official app. PLEASE.

Or Swisscom could hire me to implement this feature in their official app. I’m a freelance developer and I’m available!

Some tech details

On the server a Perl script fetches the data (via cron) from the Swisscom and stores the numbers in a MySQL database (any DB would work).
The iOS app calls a PHP script on the server to access the data: the PHP scripts fetches the data from the database and returns a JSON object.

Have fun!

PS: of course I can wait to return home and check my calls on my phone, but where’s the fun? 😉

I wrote this app 2 years ago and I still use it.

(this is a longer version of the original post)

Redirect NSLog to a file on the iPhone

If you need to debug your app when disconnected from your Mac (and from the console), redirect all your NSLog calls to a file so you can later read it.

The method below will create a file name « console.log » in the Documents folder of your application so you can later read it.

Just call this method in your program:

- (void) redirectConsoleLogToDocumentFolder
{
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                                                       NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  NSString *logPath = [documentsDirectory 
                       stringByAppendingPathComponent:@"console.log"];
  freopen([logPath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
}

The log will never be erased, so use with caution.

Lire la suite…

Macros for Xcode

These are some of the macros I use with Xcode:

CMLog: I use this macro to replace NSLog:

#define CMLog(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__,[NSString stringWithFormat:format, ## __VA_ARGS__]);

When you use this macro, it outputs text to the console, including the class and method from where it was called. So, if you call this macro from the class MyAppDelegate and the method applicationDidFinishLaunching,

CMLog(@"My iPhone is an %@, v %@", [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion]);

you get this in the console:

Lire la suite…

HowTo fit text inside a UIWebView

If, like me, you want to make sure your text will fit inside your UIWebView (without scrolling), you can implement the following javascript:

    <script language='javascript' type="text/javascript">
    function adjustHeight(maxHeight) {
      elem = document.getElementById("sign");
      height = elem.offsetHeight;
      current_size = elem.style.fontSize.replace('px','')/1;
      while ((current_size-- > 10) && (height > maxHeight)){
        elem.style.fontSize = current_size + 'px';
        height = elem.offsetHeight;
      }
    }
    </script>

Lire la suite…