Archive for the 'programmation' Category

quelques notes sur le développement d’applications iPhone

mai 08 2010 Published by admin under programmation

Voici quelques notes prises lors de mon auto-apprentissage sur le développement d’applications iphone.

En effet, étant du genre « c’est quoi déjà? », j’ai regroupé quelques informations dans cet article afin de pouvoir centraliser certaines informations que j’ai trouvées pertinentes… En espérant que cela puisse vous aider aussi.

L’essentiel des informations étant en anglais, j’ai donc laissé l’information dans la langue originale.

Some Objective-C stuff

  • When declaring a method, « - » is fr instance methods, « + » is for Class methods.
  • If you message nil, it returns zero.
  • with NSString inValue returns 0 if it’s not an integer. If it starts with an integer but followed by « crap » (9873ikdi) it will return the integer (9873). Same thing with floatValue, doubleValue…
  • If you overwite the -(id) init method, always return the result of [super init].
  • when release method is called, the retain count is decreased, if it’s zero then the dealloc s called
  • never call -(void)dealloc directly, except if you overwite the -(void)dealloc method, you should call [super dealloc].
  • if your method returns an object that you created in the method:
    • use the [newObject autorelease] or
    • prefix your method name with « alloc », « copy » or « new » to inform the developer that he will have to release it
  • balance the number of retain and release
  • If you use autorelease, the object will be put in the autorelease pull. At the end of the event handling cycle,  the autorelease pull will call the release method on the objects in the pull, and if the retain count hits 0, the object is deallocated)
  • « attribute.property = value » will call the setter, but « property = value » will access the property directly
  • you can overwite -(void) awakeFromNib method in your AppDelegate to initialize values

From « iPhone Application Programming Guide« 

  • When your application quits, you should save out information about your application’s current state in addition to any unsaved data. At launch time, you should look for this state information and use it to restore your application to the state it was in when it was last used.
applicationDidFinishLaunching: Use this method to restore the application to the state it was in during the previous session. You can also use this method to perform any custom initialization to your application data structures and user interface.
applicationWillTerminate: Use this method to save any unsaved data or key application state to disk. You can also use this method to perform additional cleanup operations, such as deleting temporary files.
  • All applications should respond to this notification and do their part to help relieve the memory pressure. For information on how to handle such notifications in your application, see “Observing Low-Memory Warnings.”
  • Icon.png is mandatory
  • an application can be interrupted by an incoming phone call, an SMS message, a calendar alert, or by the user pressing the Sleep button on a device.(…) If the user decides to take a call or reply to an SMS message, however, the system does proceed to terminate your application.
  • A keychain is a secure, encrypted container for passwords and other secrets. The keychain data for an application is stored outside of the application sandbox.
  • Avoid writing cache files to disk. The only exception to this rule is when your application quits and you need to write state information that can be used to put your application back into the same state when it is next launched.
  • Unlike most desktop applications, where the user manually chooses when to save files to disk, your application should save changes automatically at key points in your workflow. Exactly when you save data is up to you, but there are two potential options. Either you can save each change immediately as the user makes it, or you can batch changes on the same page together and save them when the page is dismissed, a new page is displayed, or the application quits. Under no circumstances should you let the user navigate to a new page of content without saving the data on the previous page.
  • If your application accesses the network using the Wi-Fi radios, you must notify the system of that fact by including the UIRequiresPersistentWiFi key in the application’s Info.plist file. The inclusion of this key lets the system know that it should display the network selection panel if it detects any active Wi-Fi hot spots. It also lets the system know that it should not attempt to shut down the Wi-Fi hardware while your application is running.
  • UIView:

View class hierarchy

NSFetchedResultsController: A « helper » controller between TableViewController and Core Data.

  • Load data lazily
  • multiple NIBs so you don’t load everything at the same time
  • Every controllers can receive didReceiveMemoryWarning… By default, it will unload all the views that are not on screen… So ViewDidLoad can be called more than once (at te beginning and after a memory Warning when the view needs to be reloaded)

More to come from the « iPhone Human Interface Guide« …

Sources:

http://developer.apple.com/iphone/index.action

http://deimos3.apple.com/WebObjects/Core.woa/Browse/itunes.stanford.edu.3124430053.03124430055

No responses yet

Ma première application iphone

avr 26 2010 Published by admin under programmation

Première application iphone

Et oui, il faut bien commencer un jour, je viens de finir ma première application iphone…

Pas très créatif (une simple calculatrice), pas de quoi être fier (de nombreuses améliorations sont possibles, notamment cacher le clavier une fois terminé…), mais tout de même… Pour une première application pour tester et apprendre objective-C, XCode, c’est pas pire, non?

Il me reste encore beaucoup de lecture à faire, notamment le « iPhone Human Interface Guideline« …

Un souvenir, histoire de rire de moi si je fais mieux dans quelques semaines ou quelques mois…

No responses yet

Geolocalisation

avr 11 2010 Published by admin under programmation

Il y a longtemps que je voulais jouer avec la Geolocalisation, j’ai donc monté ce mini-site afin de tester différentes méthodes de géolocalisation:

  • geoIP: librairie PHP
  • Google Maps v3: aucune magie ici (pas de la geolocalisation), mais il y a possibilité d’utiliser les fonctionnalité GPS de l’équipement. Le « sensor » GPS n’est pas utilisé sur mon site, mais google Maps est utilisé de 2 façons:
    • pour ajuster les résultats des autre méthodes de géolocalisation (la « pin » est déplaçable)
    • comme méthode par défaut: un outils de recherche à la google Maps (en extrêmement simple simple simple) est offert
  • Google Gears
  • la geolocalisation des navigateurs « qui ont de l’allure » (firefox, safari) (navigator.geolocation.getCurrentPosition()). Lire https://mozillalabs.com/blog/2008/10/introducing-geode/ pour plus d’info sur l’implémentation dans firefox
  • Google Ajax API: en plus d’avoir accès à pleins de fonctionalités comme Google Maps, Feeds, Search, Earth, google Friends, etc… cette API permet aussi faire de la localisation  (merci à Marc Grabanski)

En plus, j’ai utilisé 2 API « géolocalisées »:

Vous pouvez assayer le tout l’URL suivante: http://geo.fruitsoftware.com/

Amusez-vous!

One response so far

Merci Symfony

avr 11 2010 Published by admin under programmation

Il était une fois…

IL était une fois une équipe qui réalisa un site web pour un client. Tout se passa normalement au cours du développement.
Mais un jour, alors que nous devions mettre sur le serveur du client, nous apprîmes (oui, oui! apprîmes) que:

  • le serveur du client était en fait 2 serveurs,
  • ces 2 serveurs étaient « load-balancés » (pas de » sticky-tcpip » possible)
  • la gestion des sessions PHP était « basique » (file)
  • nous n’avions pas la possibilité de changer la configuration des 2 serveurs (pour utiliser memcached par exemple) ou du « load-balancer »

(je vous passe les détails de mauvaises communications entre les équipes techniques en jeu…)

Horreur!

Qu’allons-nous devenir?

Que faisons-nous?

OMG!

Heureusement…

…tel le petit poucet qui avait pris soin de mettre des pierres dans ses poches, nous avions développé notre site avec le framework Symfony (1.4).

Il est possible de changer très facilement la manière dont sont sauvegardées les sessions PHP avec Symfony, grâce au fichier factories.yml.

Il n’a donc pas fallu plus que 30 minutes pour changer la manière de gérer les sessions!

Merci à…

Notes

  1. Oui, je sais, j’ai mis un « S » majuscule à « Symfony », c’est pour m’habituer.
  2. « … et à la fin, ils firent pleins de projets Symfony. »

One response so far

Symfony 2.0 – Notes

mar 06 2010 Published by admin under programmation

Some thoughts about Symfony 2. I didn’t play with the sandbox yet, I just read the doc and browse the code (a little bit). So more to come…

routing « inheritence »

One main routing file that can include to other routing files

# hello/config/routing.yml
homepage:
  pattern:  /
  defaults: { _bundle: WebBundle, _controller: Default, _action: index }

hello:
  resource: HelloBundle/Resources/config/routing.yml

Components are actions, yeah!!

Everything is an action, and you can include an action into a template. That’s great, no need to define an action that just include a component (when you need some ajax but the first load is not ajax)

Generating Links

The generate() method takes the route name and an array of values as arguments.

Mmm, I hope there is another way to generate a route, using the controller name and action name (like the old « url_for »…). I think it’s part of the « kill the magic » cleanup…

Assets and links to images, css, js…

<img src="<?php echo $view->assets->getUrl('images/logo.png') ?>" />

You will be able to change the URL root path of your web app without breaking any links. I love it, but HTML integrators will complain… But I like it… and they will (have to?) live with that.

« imports » directive in Configuration file: cleaner configuration files!

#in config_prod.yml
imports:
  - { resource: config.yml }

No responses yet

Facebook Connect, friends et autres plaisirs…

jan 10 2010 Published by admin under programmation

Bon, autant le dire tout de suite, c’est pas facile!! Le but de la manip est de pouvoir choisir un fb friends parmi une liste (et garder le friend choisi dans un champ hidden d’un formulaire).

1ère tentative

utiliser l’API PHP (wrappé dans le plugin symfony sfFacebookConnectPlugin). Il est possible d’obtenir la liste de des uid des friends.

<code>sfFacebook::getFacebookFriendsUids();</code>

(ou accéder au Facebook::getFacebookClient->fql_query($the_query) pour faire une requête fql)

Puis utiliser fb:profile-selector ou fb:name:

<code><fb:profile-pic linked="false" uid="'. $friendUid .'"></fb:profile-pic></code>

Mais là j’ai vite vu que j’allais avoir besoin de javascript pour faire du paging. Et loader toutes les images est trop lent.

(Essayer) d’utiliser fb:friend-selector

Là, ça m’a pris du temps avant de me rendre compte qu’on ne pouvez pas l’utiliser directement dans une application facebook Connect. Cela ne peut servir que pour envoyer des invitations (et encore, fb avise que cette fonctionnalité va changer). Ps utlisable avec fb Connect car l’id du friend selectionné est dans un form dans un iframe, il n’Est pas dans la page fb Connect. Il n’est donc pas dans le formulaire de ma page, celui que je veux soumettre. Voici quand même le code:

</code><code>$field = sprintf(<<<EOF
<fb:serverfbml height="200px">
<script type="text/fbml">
<fb:fbml>
<fb:friend-selector  name="%s" idname="%s">
</fb:friend-selector>
</fb:fbml>
</script>
</fb:serverfbml>
EOF,
$name,
$this->generateId($name));</code><code>

Je le redis: ce code ne fonctionne pas avec facebook connect si vous voulez avoir un champ hidden contenant le friend choisi!

Option 3 – En cours

Mais je reviens à la base, car je ne pense pas qu’il y ait d’autre possibilité pour l’instant. Je vais utiliser le fql en javascript pour faire un ajax input field (du genre « auto-completion »). Voici le fql qui contient toute la magie. Dès que j’aurais le widget symfony, je le posterai:

SELECT uid, name FROM user WHERE strpos(lower(name), 'ka') = 0   AND
 uid IN (SELECT uid2 FROM friend WHERE uid1 = 718562059)

Il n’y a pas de « LIKE », donc on fait avec ce qu’on a, hein?

Liens:

Mise à jour (15 février 2010)

J’ai créée un plugin jquery qui permet de sélectionner un ami. Lire l’article suivant pour plus de détail.

One response so far

Paging, number of items per page and offset

août 27 2009 Published by admin under Non classé,programmation

  • page: X
  • nb_per_page: Y
  • => OFFSET = (X-1)*Y
  • =>OFFSET = (page-1)*nb_per_page

Easy, no?

2 responses so far

geocoding, latitude, longitude and distance

mai 13 2009 Published by saadtazi under programmation

from http://code.google.com/intl/fr-FR/apis/maps/articles/phpsqlsearch.html:

Here’s the SQL statement that will find the closest 20 locations that are within a radius of 25 miles to the 37, -122 coordinate. It calculates the distance based on the latitude/longitude of that row and the target latitude/longitude, and then asks for only rows where the distance value is less than 25, orders the whole query by distance, and limits it to 20 results. To search by kilometers instead of miles, replace 3959 with 6371.

SELECT id, ( 3959 * acos( cos( radians(37) )
* cos( radians( lat ) ) * cos( radians( lng )
  - radians(-122) ) + sin( radians(37) )
       * sin( radians( lat ) ) ) ) AS distance
FROM markers HAVING distance < 25 ORDER BY distance
LIMIT 0 , 20;

No responses yet

Google Analytics API – Enfin (too soon?)

avr 23 2009 Published by saadtazi under programmation

Et oui, tu le voulais pour Noël, Google l’a fait: Google vient de lancer une API pour accéder en lecture seulement les données de Google Analytics: http://analytics.blogspot.com/2009/04/attention-developers-google-analytics.html

Pour l’instant, il y a une librairie Javascript, Java et « Raw » (HTTP et XML). Pour PHP, il va falloir attendre un peu, mais on peut espérer que Zend inclut sous peu à son component Zend_GData des classes spécifiques pour Google Analytics. Il est déjà possible de s’autentifier avec le framework et d’optenir le XML à peu de frais (voir ce lien par exemple tiré de analyseweb.fr, merci Julien Coquet)

No responses yet

Zend, the good, the bad and the ugly

avr 20 2009 Published by saadtazi under programmation

Bon, le framework Zend c’est bien, très bien même. Ne me faites pas dire ce je n’ai pas dit, ok?

Mais quand même, une mini-liste de chose que je n’ai pas été capable de faire avec le Zend framework (1.7):

  • Zend_Feed: créer un feed atom custom, avec mes propres tag et namespaces. En fait, c’est faisable, mais qu’est ce que c’est compliqué…
  • Zend_SOAP:  ajouter un header du coté du client pour « consommer » un Web Service. Là, j’ai été obligé de me servir de SoapClient (inclus maintenant dans PHP). Je n’ai vraiment pas trouvé comment. Pas trop grave, car Zend_Soap n’est qu’un « wapper » de SoapClient et SoapServer (du propre aveu de Matthew Weier O’Phinney au la conférence PHP Québec).

Sinon, je me sers souvent de Zend_Mail, parfait, parfait, parfait. Zend_Amf, les tests ont été très concluant, la suite dans un prochain épisode.

No responses yet