extended attributes, spotlight and xcode screenshots

If you shall find yourself wondering, as i did, how exactly does Xcode know which device too what screenshot from the ones it manages the answer is simple, it just saves extended attributes for the files with the device id under com.apple.DTDeviceKit.screenshot.device_id e.g.

[valexa@VAiMac:~] $ xattr -l /Volumes/Storage/Screenshots/Screenshot 2010.07.13 01.43.57.png
com.apple.DTDeviceKit.screenshot.device_id: 5a14571ebe34512345b7345e13454a

Finder being finder has no way whatsoever to display or search for extended attributes, however some useful spotlight metadata is saved (the spotlight metadata itself used to be saved as extended com.apple.metadata attributes and xattr is still the only way to edit it) :

[valexa@VAiMac:~] $ mdls /Volumes/Storage/Screenshots/Screenshot 2010.07.13 01.43.57.png
….
kMDItemPixelHeight = 1024
kMDItemPixelWidth = 768
….

This can in fact be searched with finder even if not readily apparent, you have to add a specific Raw Query for it to understand the raw commands that you would have given to mdfind e.g.:

[valexa@VAiMac:~] $ mdfind -onlyin /Volumes/Backup kMDItemIsScreenCapture == 1
/Volumes/Backup/10.8/Screen Shot 2012-03-03 at 12.00.30 AM.png

This searches for screenshots taken from your mac (you can search for specific types for example whole screen ones with kMDItemScreenCaptureType == “display”, screenshots taken of specific windows with kMDItemScreenCaptureType == “window” or “selection” etc)

I had to do this because my screenshots folder contains both the Xcode ones and my mac screenshots, my specific goal was to figure out why some iOS screenshots there no longer showed under their corresponding devices, it turns out that i edited some with Photoshop and it replaced the extended attributes.

Editing those attributes with finder and AppleScript while possible is extremely convulted and employs shell calls anyway so we just head back to Terminal with the newfound knowledge of what screenshots we have.

Now if you only have one device for each screen resolutions available in iOS you are in luck, to print the extended attributes for iPhone, iPhone Retina, iPad, iPad Retina respectively, you can do:

mdfind -onlyin /Volumes/Storage/Screenshots/ “kMDItemPixelWidth == 480 || kMDItemPixelHeight == 480” -0 | xargs -0 xattr -l
mdfind -onlyin /Volumes/Storage/Screenshots/ “kMDItemPixelWidth == 960 || kMDItemPixelHeight == 960” -0 | xargs -0 xattr -l
mdfind -onlyin /Volumes/Storage/Screenshots/ “kMDItemPixelWidth == 768 || kMDItemPixelHeight == 768” -0 | xargs -0 xattr -l
mdfind -onlyin /Volumes/Storage/Screenshots/ “kMDItemPixelWidth == 1536 || kMDItemPixelHeight == 1536” -0 | xargs -0 xattr -l

Now that you seen your device id’s of the screenshots with proper attributes you can go ahead an set the proper id for all screenshots for a screen type e.g.:

mdfind -onlyin /Volumes/Storage/Screenshots/ “kMDItemPixelWidth == 480 || kMDItemPixelHeight == 480” -0 | xargs -0 xattr -w com.apple.DTDeviceKit.screenshot.device_id ‘5a14571ebe34512345b7345e13454a’

Xcode will immediately catch on the change and credit the screenshot properly for it’s source device.

iOS and vectorial artwork

Any conscious iOS developer wants his artwork to look as good as possible, and with the retina display for example we were told to upgrade our artwork to higher resolution, which involved alternative @2x versions for each file and gets daunting fast if you have a lot of artwork files, and especially if a lot of your artwork is vectorial and you could just use it directly.

A popular vectorial format is PDF, and Apple has implemented a lot of the resolution independent artwork in their OSX apps as PDF, unfortunately there is no straightforward way to do that, the iOS SDK does not yet have the PDFKit.framework that exists on OSX (Interface Builder does still accept pdf files as images but they will not show on iOS) so what is there to do ?

Well the only way to do it currently is to set your artwork images in code, after rendering the PDF file into a UIImage, there are a couple of approaches to this and i am going to show you the one i use :

#include <dlfcn.h>

-(UIImage *)UIImageFromPDF:(NSString*)fileName size:(CGSize)size{
    CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), (CFStringRef)fileName, NULL, NULL);
    if (pdfURL) {
        CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(pdfURL);
        CFRelease(pdfURL);
        //create context with scaling 0.0 as to get the main screen's if iOS4+
        if (dlsym(RTLD_DEFAULT,"UIGraphicsBeginImageContextWithOptions") == NULL) {
            UIGraphicsBeginImageContext(size);
        }else {
            UIGraphicsBeginImageContextWithOptions(size,NO,0.0);
        }
        CGContextRef context = UIGraphicsGetCurrentContext();
        //translate the content
        CGContextTranslateCTM(context, 0.0, size.height);
        CGContextScaleCTM(context, 1.0, -1.0);
        CGContextSaveGState(context);
        //scale to our desired size
        CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1);
        CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page,kCGPDFCropBox,CGRectMake(0,0,size.width,size.height),0,true);
        CGContextConcatCTM(context, pdfTransform);
        CGContextDrawPDFPage(context, page);
        CGContextRestoreGState(context);
        //return autoreleased UIImage
        UIImage *ret = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        CGPDFDocumentRelease(pdf);
        return ret;
    }else {
        NSLog(@"Could not load %@",fileName);
    }
    return nil;
}

Typically you would use it like this : [someButton setImage:[self UIImageFromPDF:@”search.pdf” size:CGSizeMake(20,20)] forState:UIControlStateNormal];

The best thing about this is that it not only makes your artwork compatible with the current form and scaling factors, but most likely with further ones as well.

This is compatible with iOS 3.0+ and has been tested on iPhone and iPad, it is compatible with any resolution scaling (retina display has 2.0 for example) , i have also attached 4 pdf icons to get you started (created with Photoshop, exported with no layers or color profiles).

If for some reason you do not want to #include dlfcn.h and use dlsym() you can weak link UIKit and just check if UIGraphicsBeginImageContextWithOptions is NULL, or obviously if you are not supporting anything before iOS4 remove the conditional altogether.

NOTE: technically on IOS 4  you can currently exploit a bug and load a pdf file from [UIImage imageNamed:@”filename”] by stripping the extension, however the default size of the artwork in the pdf has to be exactly the size of the UIImage you want, if it gets scaled significant pixelation occurs basically making this shortcut unfeasible, plus it could stop working altogether at any time.

iphone signal testing with code

Closest cell tower 1 Km, iPhone 3G, Wi-fi mode, iOS 4.0, Orange network.

With device held gently by edges:

signal avg 90 (outdoor, line of sight to cell tower, same altitude)
signal avg 😯 (indoor, line of sight to cell tower, same altitude)
signal avg 60 (indoor, no line of sight to cell tower, same altitude)
signal avg 4O (outdoor, no line of sight to cell tower, ground level)

With device cradled in hand a average decrease of signal by about 20 in all cases and whatever finger configuration.

Turning 3G on causes a average decrease of signal by 5 in all cases.

The connection strength bars shows 5 bars in all cases.

Absolute minimum experienced : 19, absolute maximum 96.

The thing to take away from all this is that if  you already had a very bad connection under 20 and subtract the hand attenuation of about 20 you are left with no signal, and it did not hep that until iOS 4.0.1  a bad connection with a 20 strength would have shown 4 or even 5 bars.

The application used to test gets the signal strength from private calls to apple’s CoreTelephony framework, in a effort to help the iphone signal testing going on share a common base i am providing the application to anyone, please let me know what are the results of your tests and feel free to contribute to the code on github.

The application is named  VAFieldTest , it’s code is under a open source license and can be found at http://github.com/valexa/VAFieldTest , you need Xcode and a iPhone developer account to compile and run it.

iOS 4.0.1 update
same behavior as before, with the difference that now the connection bars properly reflect changes in the strength (I 1-19, II 20-29, III 30-39, IIII 40-49, IIIII 50-99 ) , with previous versions they just show 5 bars for any signal strengths above 25.

Safari-like Reader for any browser including Mobile Safari

We all like the new feature in Safari 5, Reader, well maybe except the advertisers, it is so pristine as anything we would expect from Apple but as it turns out it is actually based on the work of NYC based design house arc90, namely Readability which is acknowledged by Apple in file:///Applications/Safari.app/Contents/Resources/Acknowledgments.html

If you visit their Readability page you will notice that it is implemented as a javascript bookmarklet useable in any browser (i tested Chrome and Firefox) , all you have to do is drag the link to the bookmarks bar, for Mobile Safari which does not have such a bar it is a bit more complicated:
1 – create a placeholder bookmark by pressing plus (can be any page), press Save
2 – copy the javascript at the bottom of this post into the pasteboard
3 – press bookmarks > press edit > press the arrow on the shortcut you created
4 – press the round x to clear the name and type say Readability
5 – select the bottom field, press the round x to clear the address and paste the text

javascript:(function(){readStyle='style-newspaper';readSize='size-medium';readMargin='margin-wide';_readability_script=document.createElement('SCRIPT');_readability_script.type='text/javascript';_readability_script.src='http://lab.arc90.com/experiments/readability/js/readability.js?x='+(Math.random());document.getElementsByTagName('head')[0].appendChild(_readability_script);_readability_css=document.createElement('LINK');_readability_css.rel='stylesheet';_readability_css.href='http://lab.arc90.com/experiments/readability/css/readability.css';_readability_css.type='text/css';_readability_css.media='all';document.getElementsByTagName('head')[0].appendChild(_readability_css);_readability_print_css=document.createElement('LINK');_readability_print_css.rel='stylesheet';_readability_print_css.href='http://lab.arc90.com/experiments/readability/css/readability-print.css';_readability_print_css.media='print';_readability_print_css.type='text/css';document.getElementsByTagName('head')[0].appendChild(_readability_print_css);})();

Now when you want to see only the content on a page you are visiting just tap the newly created bookmark and you are all set.
Just in case you want to enhance your Mobile Safari even more you might want to check out http://ipuhelin.com/en/safariplus/ ,in page text search is a must-have if you ask me.

Seesmic before the iPad

Exactly 2 years ago Seesmic purchased Twhirl and shifted from a video conversation platform to a twitter client, i will continue to make a brief overview of the process as it provides a extremely interesting and relevant case.

I started following Seesmic when it was still a video site, behind it is Loic Lemeur a well known entrepreneur highly involved in social media and the father of the LeWeb conference, when he started Seesmic he even moved to San Francisco getting people like Pierre Omidyar, Reid Hoffman, Stephen Case on board and two series of founding $6M each.

By this time there still was no business model but Loic’s goal was to have a impact and create value and like every investor knows, that eventually blooms into a business, by the end of 2008 however there were already signs of trouble with 1/3 of staff being laid off, early into 2009 a web version of Seesmic’s twitter client was released then silence until early 1010 when Loic used Microsoft’s Professional Developers Conference as a platform to launch Seesmic for Blackberry and Android, which signaled the shift toward Windows, Loic himself switching to Windows after complaining about issues upgrading OSX to Snow Leopard.

The mobile and web versions joined the initial desktop Seesmic twitter client that ran on both Windows and OSX courtesy of Twirl’s Adobe Air codebase, so by now you could say that they had everything covered, except one minor thing, the iPhone, and in two days from now the iPad, which brings me to the reason why i started writing this.

Sure, you could argue that they identified the niche in the lucrative and less competitive Blackberry/Windows space, apparently they quickly hired a bunch of romanian windows developers and eventually even partnered with Microsoft to create a windows only flavor of Seesmic for the masses, Seesmic Look, so they could afford to ignore iPhone and the iPad markets, saturated with independent developers and highly competitive, even if Loic had the founds and the levers to give it a edge over anyone else.

Either way Seesmic makes for a extremely interesting case study, i gave up waiting for a native OSX/iPhone client, but things are not looking good for the days ahead, here is how it will look: people opening seesmic.com from a iPhone and more importantly from the iPad will be thrown into a dead-end with broken image links and suggestions to get the Android and Blackberry clients, even if they know the url to the web based Sesmic client they will be unable to access it from mobile browsers, and there is no native Sesmic in the AppStore either, which brings the options to 0.

enabling iPhone tethering on Orange

Here is how carrier free charge tethering looks and is done with Orange Romania

iphone

rename ~/Library/iTunes/iPhone Carrier Support/Orange_ro.ipcc to Orange_ro.zip extract and enter Payload and bundle dirs , open Carrier.plist

plist

edit the apns section like in the screenshot , optionally edit the other 2 plists changing BundleVersion from 2.5 to 5.0, save and close all plists

compress the Payload dir an rename the archive to .ipcc , alt+click Restore in itunes and select it after typing

defaults write com.apple.iTunes carrier-testing -bool TRUE

in terminal then just reboot the iphone

mac

i have tested both usb and bluetooth , working great , the ipcc file is atached

2010 UPDATE :  THIS DOES NOT WORK ANYMORE

iphone and flash

Ok so i have to quote and comment on the following from informationweek : ^

Jobs’ statements are sure to disappoint Web developers, many of whom are familiar with Flash development

I am a web developer and i am not disappointed at all by his statement which for the record was straight on and amounted to :

“Flash is not yet good enough for the iPhone,”

Now i certainly do not know who advises Jobs , but i can tell you that a software engineers or web developer will agree with him on that , only the web designers and entrenched corporate entities might differ but that is another story.
And even them benefit from the fact that Jobs is pushing innovation by forcing adobe to improve the inners of the flash mess and not helping it’s monopoly over web content delivery systems.
Either way the folks at information week could use a touch of pertinence while delivering their comments.
That is to say in plain words that are either idiots or they are pushing agendas like any corporate monkey.
And here are quotes of comments on their own article page from people that probably developed with flash too instead of only looking at flash content as a way to make them experts on it.

Derek commented on Mar 5, 2008 4:13:57 PM Jobs is right – flash sucks. Ever try decompiling a swf file? It’s painful and arcane. Flash is ok from a user experience level and more efficient from a download perspective but the tools and formats for it are voodoo.

Webwin commented on Mar 5, 2008 4:16:24 PM Right on – I’m a developer and HATE dealing with Flash. It’s simply not open enough and as the previous poster mentioned – voodoo to some extent. As a developer I hate blindly writing to formats that aren’t open.

Shane Johnson commented on Mar 5, 2008 4:18:46 PM I’m surprised that so many sites use Flash myself. It’s about time someone stuck a flag in the ground out of defiance. There MUST be a better way to deliver video content than Flash.

kurt Witcher commented on Mar 5, 2008 4:38:18 PM I think a big problem with flash is the huge amount of processing power it takes to run. I’m guessing flash in its current form would drain the iphones battery probably 3 times faste, just so we can watch our online advertising bounce.