Categories
Computing iphone Mac OS X

Private methods in Objective-C

Coming from the Java world, I love, care and embrace all things private, including private methods. Objective-C supports the feature but it appears to me (based on very shallow Googling) that there is not too much familiarity (or use) with it. I looked in a book I recently acquired, Learn Objective-C for Java Developers (Learn Series). While not a book a perfect book, it does cover the how-to of private methods in Objective-C.  

The key to the approach is to leverage Objective-C categories. Categories are a mind-blowingly nifty in the fact that they allow you, among other things, to augment objects you did not create with your own methods. While there are other ways of 'hiding' private methods, most of them result in warnings in Xcode. So here goes…

Say you have an object called CoolWidget. You create the header file (CoolWidget.h)for it as usual, i.e.:

@interface CoolWidget:NSObject
{
    int publicVar;

    @private
    int somePrivateVar;
}

// public methods
-(void) doSomething:(BOOL)cool;

@end

To add private methods to it, you would create a category for the object in a separate header file (CoolWidget+Private.h):

@interface CoolWidget (Private)

// private methods
-(void) doSomethingPrivate:(BOOL)cooler;

@end

All that's left for you to do is to include the additional header file, CoolWidget+Private.h in your implementation file, CoolWidget.m (though categories are often/normally implemented in their own .m file).

Update:

As my friend Glenn Barnett points out in his tweet, there is no such think as private methods in Objective-C. Unlike C++ or Java, there is no real 'enforcement' of access to the methods. Privacy, overall, is purely by convention. 

Share
Categories
Computing iphone

How to export contacts from a Nokia device to Gmail

I got my wife an iPhone this week. She used my old Nokia N95-8GB when we both decided we were fortunate enough that we could afford to get her an iPhone. The (virtual) keyboard and overall capabilities of the device just overwhelm compared to the Nokia.

Still, her contacts were on the Nokia and needed to be moved to the iPhone. Since her new iPhone uses micro-SIM cards, the Nokia's full size SIM could not (easily) be removed and moved to the iPhone. Software was our hope.

Google provides synchronization with mobile devices using the Microsoft Exchange ActiveSync protocol. To achieve that, the Nokia is expected to have Nokia's Mail for Exchange application installed. The Nokia had version 3.0.0.0 of Mail for Exchange (MfE) and sadly failed to sync no matter how many times I tried. Ironically, Nokia has a Sync application that works with their Ovi Contacts website. Sadly, Ovi Contacts does not appear to have an export capability for the contacts it holds. 

So how do you do it?

My N95-8GB came with a software application on the CD called Nokia Nseries PC Suite. I believe it is similar to the Nokia PC Suite distributed today. I installed the application on my PC (no Mac version, sadly) and connected my phone. I started the application, which detected my device. I then clicked the tools button, and finally 'Nokia PC Sync'. PC Sync will then ask you if you wanted to synchronize your phone's calendar and contacts with Outlook, Outlook Express (which relies on Windows' Address Book installed on any Windows XP and newer machine) or variations of Lotus Notes. I chose Outlook Express as I do not have Outlook installed. The application then proceeded to ask me which address book to export to and then once confirmed, the application synced. 

Once synced, I disconnected the phone from the computer and opened Address Book. The application immediately showed the new contacts imported from the phone. Under the File menu, Address Book has the ability to Export. Select 'Other Address Book' and then select 'Text File (Comma Separated Values)'. Pick a location on your computer and Address Book will create a .csv file there.
Update (8/19/2010): Apparently Windows Address Book on Windows XP, at least, does not export mobile numbers in its export function. To achieve this feat you need to install Windows Live Mail. Windows Live Mail required me to uninstall a previous version of the Windows Live Essentials suite I had already but after doing that, it installed fine. Windows Live Mail comes with what apparently became Windows 7's address book – Windows Live Contacts. Windows Live Contacts, in turn, reads Windows Address Book's files but is able to let you export the correct fields – most importantly, mobile phone number.

To do that, open Windows Live Mail and select 'Contacts' from the application bar on the bottom left hand side. The contacts window will open. Now, press ALT+M or click the menus button. Select 'Export' and 'Comma Separated Values (.CSV)' from the sub-menu. A window will pop up asking you for a file name and location for the exported contacts file. Select one and click 'Next >'. You will now have the option to select what fields or contact attributes you would like to export. Scroll down the list and make sure that the 'Mobile Phone' field is checked. Click 'Finish' and the application will create the CSV file you need in order to import your contacts to Gmail.

Finally, go to Gmail and log into your account. Click 'Contacts' from the menu on the left. Your contact list will appear. On the contact list menu, click 'More Actions' and then 'Import…'. A popup will ask you to select a .csv file. Select the one you created with the Address Book application and click the 'Import' button. Google will read the file and voila – your contacts will be part of your Gmail account. This account can in turn run synchronized with your iPhone. 

Share
Categories
Computing iphone

Geo-tagging photos on the iPhone: feature added, killed.

I love taking photos with my phone. Phone cameras turn you into a mobile content generation unit. Snap photo, upload, the world knows. Never mind the fact that the world knows about your cat being cute or your son's nose being very congested. Phone cameras become double powerful when coupled with the phone's GPS. The GPS stamps each photo's EXIF data, the same metadata that records when you took the picture, with where you did it. So in essence, you need two elements: upload and location-recording capabilities. My Nokia N95 had both capabilities. Great camera, GPS, uploads to Flickr and Nokia's Ovi. Then Nokia stopped developing apps for the phone, which is very disappointing. Its general slowness and the arrival of the iPhone 3Gs convinced me to move on. The iPhone compensates for middling camera hardware with speed and processing power. And it had a stellar app called PixelPipe. PixelPipe batch uploaded my photos and videos to any site I wanted. And little did I appreciate it at the time, but it also retained and uploaded the geotagging data from photos. Pixelpipe was recently removed from the iPhone's app store. Apparently it accessed photos using the wrong element (in Apple's eyes) of the iPhone SDK. That made the app better for batch uploads, but played against 'the rules'. So I was left looking for alternatives. Without mentioning all of them, Flickr's app is the most disappointing to me. Flickr's app's beautiful design, sensible usability, stable, but with one (probably imposed) 'feature' bug: it tags whatever photos it uploads with the location of *the upload*. In other words, if you took the photo in Japan and uploaded it in Omaha as- Mt. Fuji will be geotagged as being in Nebraska. Now why would Flickr, a great Website I love and pay for, do such a boneheaded thing? Because apparently that's the best the iPhone allows. It seems like the iPhone SDK forces developers to access photos using specific APIs that remove the location data from images. If you actually take a picture and then upload it immediately using the Flickr app allows the app to append the currrent location back to the photo. Absurd, no? So what's left? iPhoto and other desktop applications that get the actual phtoto files from the iPhone can still get the location data from the actual files. But on the iPhone, Apple made the wrong decision to remove that information. Privacy may be the concern. I am, for one, disappointed and a bit angry. I doubt Android imposes such a limitation on apps. But to follow Steve Jobs' logic from an email, I'd better create than criticize.

UPDATE:

Manage to restore PixelPipe from iTunes. It is the good version that was removed by Apple. Amazingly enough, having tweeted about it, PixelPipe asked me to send them their own iPhone app file. Probably for use with jailbroken iPhones. A bit surprising that they, of all people, will not have an old version of their own app. Still, glad I solved it by going around Apple's own restrictions. Geotagging is back for me.

Share
Share