To do list:
That’s it for now. Let’s see if I can find time to do all those.
Updated

Finally, the first release of Spaniards Mobile got released just today and it is available for download on the App Store for FREE.
More info:
http://www.spaniards.es/noticias/2009/08/29/spaniards-10-para-iphone-ya-disponible

Have you seen those iPhone apps with a reload button that switches itself to an animated activity indicator while the reload action is being performed?
Here is how to do that. Place this code on your ViewController:
-
- (void)showReloadButton {
-
UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc]
-
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
-
target:self
-
action:@selector(reload:)];
-
self.navigationItem.rightBarButtonItem = refreshItem;
-
[refreshItem release];
-
}
-
-
- (void)showActivityIndicator {
-
UIActivityIndicatorView *activityIndicator =
-
[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
-
[activityIndicator startAnimating];
-
UIBarButtonItem *activityItem =
-
[[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
-
[activityIndicator release];
-
self.navigationItem.rightBarButtonItem = activityItem;
-
[activityItem release];
-
}
-
-
- (IBAction) reload {
-
// Do your reload stuff
-
}
Seen here.
I was watching one of the video tutorials from Apple last night about some custom JS available on Safari, only on the iPhone 3.0, that let’s you interact with the phone and obtain data like the current location, etc.
So I built a little page to see how it works. I included Mootools 1.2.3 from Google servers and the Google Maps API. And voilá, with a few lines of code we have a totally functional web based GSP navigation system. A little bit ugly, but functional. Currenlty it only centers the map on the coordinates given by the phone, and also does a reverse geolocation to obtain the address (actually city, state and country). But it could be easily extended to add markers to the map, or even paths to track the movement.
If you have an iPhone (or an iPhone simulator) go to:
http://enekoalonso.com/research/iphone/geolocation.html
The source code:
-
var Navigator = new Class({
-
initialize: function() {
-
-
// Listen for position changes
-
this.watchId = navigator.geolocation.watchPosition(
-
function(position){ this.position(position) }.bind(this),
-
function() {},
-
{ enableHighAccuracy: true, timeout: 1000, maximumAge: 10000 }
-
);
-
this.infoPanel = $('info');
-
-
// Create the Geocoder and the Map
-
this.geocoder = new google.maps.Geocoder();
-
this.map = new google.maps.Map($('map'), {
-
zoom: 12,
-
mapTypeId: google.maps.MapTypeId.ROADMAP
-
});
-
},
-
-
position: function(position) {
-
// Update labels
-
this.infoPanel.getElement('p.date').set('text', position.timestamp);
-
this.infoPanel.getElement('p.coords').set('text', position.coords.latitude + ', ' + position.coords.longitude);
-
this.infoPanel.getElement('p.altitude').set('text', position.coords.altitude);
-
this.infoPanel.getElement('p.heading').set('text', position.coords.heading);
-
this.infoPanel.getElement('p.speed').set('text', position.coords.speed);
-
-
// Center map
-
var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
-
this.map.set_center(latLng);
-
-
// Reverse geolocation (get current address)
-
this.geocoder.geocode({'latLng': latLng},
-
function(results, status) {
-
if (google.maps.GeocoderStatus.OK) this.showAddress(results)
-
}.bind(this)
-
);
-
},
-
-
showAddress: function(results) {
-
// console.dir(response);
-
if (results[1]) {
-
this.infoPanel.getElement('p.location').set('text', results[1].formatted_address);
-
}
-
}
-
});
-
-
window.addEvent('load', function() {
-
new Navigator();
-
});
Enjoy.
This week I have been working on a website for iPhone phones and I have discovered some interesting things about events. I am using plain Javascript, with no third party libraries, so I don’t know if they have any fix for these issues or if they affect them.
For example, a couple of days ago I was posting how to detect the iPhone’s orientation. The problem with the method I used is that I am assigning explicitly the function to handle the event, which means only that function will handle the event. If I wanted to add a second function to handle the same event, for example inside an object, I would have to use the window.addEventListener method. But apparently addEventListener does not work on the iPhone for some events.
The following code wont work on the iPhone (although it works on the iPhone simulator)
-
function updateLayout() {
-
if (window.orientation)
-
document.body.setAttribute('class', 'landscape');
-
else
-
document.body.setAttribute('class', 'portrait');
-
}
-
-
window.addEventListener('orientationchange', function(event) {
-
updateLayout();
-
}, false);
-
-
window.addEventListener('load', function(event) {
-
updateLayout();
-
}, false);
I have found the addEventListener function works with input fields (focus and blur events), with links (click event) and with window (load event). I have found it doesn’t work on forms (submit event) neither with the custom onorientationchange event as shown avobe. I haven’t tested other events yet.
It may be that all these issues have been fixed in newer versions of the iPhone OS X – the one I have for testing is 1.1.4 (4A102).
Detecting the iPhone’s orientation on a website is very easy: the only thing needed is a little bit of Javascript to listen to the onorientationchange event:
-
window.onorientationchange = function() {
-
if (window.orientation)
-
document.body.setAttribute('class', 'landscape');
-
else
-
document.body.setAttribute('class', 'portrait');
-
}
-
window.onload = function() {
-
window.onorientationchange();
-
}
The window.orientation variable can have three different values: 0, 90 and -90. In most cases we wont mind if its 90 or -90, since both are landscape, so I have ignored this on the code above. Adding a CSS class to the body is the cleanest way to handle iPhone’s orientation. Now it’s up to you to set up the CSS for both layouts.
The resolution of the visible screen (viewport) changes drastically from portrait to layout, so be aware of this:
- Portrait visible screen: 320 x 356 px
- Landscape visible screen: 480 x 196 px
Source: Web Apps Reference Library – Handling Orientation Events (needs registration)