Make Better Things

I like to make better things.

How to take screenshot programmatically in iOS SDK

First Import QuartzCore

#import <QuartzCore/QuartzCore.h>

Then –

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
    UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);

[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
NSData * data = UIImagePNGRepresentation(image);
[data writeToFile:@"foo.png" atomically:YES];

Note that this won’t capture certain types of screen content, like OpenGL ES layers.

How to install Ruby 2.0.0 on Ubuntu 12.04 LTS

Follow below steps –

apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
tar -xvzf ruby-2.0.0-p0.tar.gz
cd ruby-2.0.0-p0/
./configure --prefix=/usr/local
make install

How to check if URL scheme is supported in iOS Safari using javascript?

There is no straight forward way to check if URL scheme is supported or not, but we can use a workaround, we can check if our page has a focus after a short timeout. We can use “pagehide” event.

var appurl = 'custom://url';
  var appstore = '';

  var timeout;
  function preventPopup() {
    timeout = null;
    window.removeEventListener('pagehide', preventPopup);
  function startApp() {
    document.location = appurl;
    timeout = setTimeout(function(){
      if(confirm('You do not seem to have the App installed, do you want to go download it now?')){
        document.location = appstore;
    }, 1000);
    window.addEventListener('pagehide', preventPopup);