Calculate age in objective-c
Posted in apple, iphone, mobile development, software on January 7th, 2010 by Hamish Rickerby – CommentsFor an iPhone application I’m developing for a client I need to capture the birthdate of a user, and then show their age on a profile screen. I went looking for a function to help with this simple and tedious task, but couldn’t find any example code that could be lifted to help me, so I rolled my own. Here is what I made, steal as you see fit.
- (NSInteger)age:(NSDate *)dateOfBirth {
NSCalendar *calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *dateComponentsNow = [calendar components:unitFlags fromDate:[NSDate date]];
NSDateComponents *dateComponentsBirth = [calendar components:unitFlags fromDate:dateOfBirth];
if (([dateComponentsNow month] < [dateComponentsBirth month]) ||
(([dateComponentsNow month] == [dateComponentsBirth month]) && ([dateComponentsNow day] < [dateComponentsBirth day]))) {
return [dateComponentsNow year] - [dateComponentsBirth year] - 1;
} else {
return [dateComponentsNow year] - [dateComponentsBirth year];
}
}
iPhone Camera Overlays + iphonearkit
Posted in apple, augmented reality, iphone, mobile development on September 20th, 2009 by Hamish Rickerby – CommentsToday I have been hacking away on the iphonearkit source available at github and have incorporated the ARGeoViewController as an overlay over a ImagePickerController with the camera as the source (which was introduced with iPhone OS 3.1). Results below.
I want to tidy up some of the code before I check it back into my clone of the source, but this is a really good basis for some smart location and direction aware augmented reality apps on iPhone. Wonder what the iphonearkit license is – it’s unclear…
— EDIT —
Bugger. It appears that zac has implemented similar functionality to me already
Bloody github and it’s slow (never!) updates to fork queues and network graphs. Oh well, maybe I won’t bother tidying my code.
Augmented Reality – Hello World
Posted in augmented reality on September 20th, 2009 by Hamish Rickerby – CommentsI’ve recently discovered augmented reality. After I saw my first “virtual business card” application I was hooked. I’ve been doing a lot of reading and experimenting with software over the past 2 days, and have got ARToolkit working here. Here are some shots of the obligitory “cube over marker” demo. I would post a video, but my screen capture software and AR software = a really poor frame rate and substandard video
Next up, something more substantial.
Kit Quiz: UK
Posted in iphone, mobile development on September 11th, 2009 by Hamish Rickerby – Comments<shameless self promotion>
My 4th iPhone application was approved yesterday by Apple, and it launches in the iTunes store today. It’s called Kit Quiz: UK and is a UK team based football (soccer) shirt quiz game. It features over 130 shirts from UK football teams, and will have more added shortly. There are 3 modes of gameplay, from the practise model “Friendly” to a time challenge “Blitz”.
It’s integrated with Twitter and Facebook so you can check out your friends scores and find out once and for all who can recognise the most football shirts.
Couple of screenshots below for anyone interested. Download it now!
</shameless self promotion>
Passenger (Ruby on Rails) + PHP on OSX
Posted in apple, internet, ruby, software, web on August 15th, 2009 by Hamish Rickerby – CommentsI’ve spent the last hour or so trying various things out to get passenger and PHP to play nicely together on my mac under OS X (Leopard) and apache2.
The situation I was finding was that PHP apps would run, but only if you explicitly call the script (ie index.php) rather than just the directory. If you called the directory, passenger would take over and give me a rails routing error.
The issue was to do with the passenger vhosts configuration. On my machine I have an number of ruby on rails apps configured with the passenger preferences pane (creating vhost entries within /private/etc/apache2/passenger_pane_vhosts/. I have enabled user_dirs, so that the users of my machine’s pages (and other apps) are served from their ~username/Sites directory.
My users configuration info for apache is installed in /private/etc/apache2/users/, and the instructions to load the configuration from that directory is stored within /private/etc/apache2/extra/httpd-userdir.conf (content below).
# Settings for user home directories # # Required module: mod_userdir # # UserDir: The name of the directory that is appended onto a user's home # directory if a ~user request is received. Note that you must also set # the default access control for these directories, as in the example below. # UserDir Sites # # Users might not be in /Users/*/Sites, so use user-specific config files. # Include /private/etc/apache2/users/*.conf
To get everything working together nicely, I merely wrapped this inside a vhosts configuration directive, and gave it a ServerName of localhost – so that this vhost would be the one that responds to requests for localhost, rather than some random passenger vhost assuming it was the boss of everything. New /private/etc/apache2/extra/httpd-userdir.conf below.
<VirtualHost *:80> ServerName localhost UserDir Sites Include /private/etc/apache2/users/*.conf </VirtualHost>
Thanks to this, all of my rails apps are served under passenger, and I can have static HTML, PHP and camping apps (previously configured – nothing to do with the above) all served from within my ~username/Sites directory.
Hope this helps someone.
Undefined method rewind and rails 2.3.3
Posted in ruby on August 4th, 2009 by Hamish Rickerby – CommentsToday I updated a project I’m working on from rails 2.2.something to 2.3.3. Then, I started getting the following wacky error.
undefined method `rewind' for #<TCPSocket:0x3631e58>
Turns out if you see this after a rails 2.3.3 update, you might just need a phusion passenger update (I was on passenger 2.1.3, apparently this error happens on passenger 2.1.2 too)
sudo gem update passenger
sudo passenger-install-apache2-module
Put the lines recommended by the install script in your apache config file, restart apache and you’re good to go.
Hope this helps someone.
USSD Codes on iPhone
Posted in apple, iphone, mobile development, telecommunications on July 31st, 2009 by Hamish Rickerby – Commentsmakeuseof.com have recently posted about 11 cool iPhone keypad codes – these are special codes (known as USSD codes) that send messages via the signalling channel direct to the core of a mobile operators network. These codes are nothing new, they have been around for years and years. They are also not generally universal (there are some standard, but they provide relatively boring functionality). Different networks can enable different functionality on different codes.
The codes can do boring things like retrieve your divert status from the network, return your IMEI or perhaps ICCID, but they can also interact with specialised applications driven via USSD Gateways to return useful information and execute transactions. These are applications that are sent specific codes by an operators core network, perform some processing on the data received, and return a response. Things that are non-standard that are enabled by USSD Gateways are services such as USSD-based prepay balance retrieval, USSD-topup, or interactions with NGIN features to alter a network based service.
I looked into USSD codes on the iPhone a while back, not to be used by users typing them in, but more to be used by applications querying information from the network via them. The reason why I wanted to programatically access them? To look at what’s possible for network operators or enterprises to release as iPhone based network service management applications.
Sadly, Apple have disable the use of USSD codes from within the (legitimate) iPhone sandbox available to developers (via the open URL methods, passing in a tel://xxxxxx URL). This means that there won’t be any applications from your operators that will make it easy to retrieve and change network settings that can be released thru the app store – at least not until Apple change their mind about interactions with USSD codes. Which is a pity – there are lots of useful services that would be useful to expose simple interfaces for usage for to the operators end users. USSD is an efficient, fast way to configure the network, using capabilities that most operators already have.




