Thursday, 14 February 2013

Android, iOS and Git: A Love Story

So I've been working with Eclipse and Xcode a lot recently after my iOS app Memorable got reviewed by Wired and I felt I should really get round to completing the port to Android. I'd worked with Eclipse before but mostly for small projects that didn't really need backing up, or at least not with repo control.

This time though I wanted to have Memorable for Android backed-up and repo controlled using BitBucket (the service I'd used for a while for my iOS projects due to it's unlimited private projects). This was problem-some enough with Xcode, as although it officially supports Git repo's it doesn't do so smoothly with constant problems.

So when it came to using Eclipse I got all exciting expecting it to support Git much better than Xcode, but discovered it really isn't. In fact it requires additional extensions to even work. This was starting to drive me mad.

Yes you can use Git with both Xcode, and Eclipse but neither is smooth and both has some annoying bugs and idiosyncrasies. So I decided to try just using Git "old-style" and via command-line. I'm now adverse to command-line tools and when using Linux often have great "fun" diving into things at the cli level but sometimes it just nicer to have a GUI for simplicity and quickness.

Along comes SoucreTree. SourceTree is a GUI client for OSX for Git and Mercurial. In a grand total of 15 minutes, I had it installed, repo's for both my iOS projects and Android projects linked to BitBucket and sync'd and began working. It also has built-in setup for BitBucket, Stash, and GitHub, all you need to do is enter your username and password and it will pull a list of all your repo's. From there to sync a product and create it as a local repo at the same time, just drag and drop the project folder onto the the interface, add the remote repo you want to use from the list, commit then push. Done in under 5 minutes.

SourceTree is not only a must have if your using any version control systems, and want to speed up development time by cutting out all the messing around with getting your repo's to work right, it also free!

Get it here


Wednesday, 18 July 2012

iPhone Battery Optimisation

As many people have commented, and you'll have probably noticed, the iPhone 4S have terrible battery life, and when I say terrible I mean absolutely awful.

My current record is around 16 hours from full charge without gaming and with less than 50% of that active usage (e.g. not having the phone sitting in my pocket). Fear not however as there is a solution. 

That may be a claim you've heard in many other places, and possibly even tried a lot of the solutions but stick with me, there is a couple a key points here which will significantly help.

So without further adue (a-due, a due, adieu, oh it's something like that); 

Kill, Kill, Kill, ...... Apps That Is

App run in the background when hit the home button or hit a Notification to another app. When they are running in the background they aren't using anywhere near as much power as they would be when they are running normally but they do use power. Especially apps that use location based services such as Pedometers, or Run Trackers. Killing an app won't lose any important information, although it may close some open events, for example in Safari it will close open tabs. 

To kill an app double press the home button in quick succession and bottom panel will open showing running apps. Now hold down anyone and they will start to vibrate and show a X much like when you try to move them normally. Now just hit that X and it will close it. Do this every once in a while and you'll save a fair amount of power. 

Don't Use Location Services When Not Needed

Some apps use location services for purposeful things, for example Maps, Pedometers (again), Run Tracker (once more again). However others apps use location services for things that we don't really need. For example my banking app does to help me find cash machines but I can just as easily enter my location manually. 

GPS swallows power. Unless you think it's crucial to the apps use, say no when asked if you want to allow it. If you already have you can re-disable specific apps (or just check what is using it) in Settings > Location Services.

Turn Off iTunes Ping

Ping is an iTunes service that was designed as Apple's music social service, but most people have never even heard of it, never-mind use it. However if you use Music on your iPhone it's sitting there in the background using power but doing nothing. 

To disable, go to Settings > General > Restrictions and Enable Restrictions. Now it should show all your apps and list them as On (meaning un-restricted), find Ping and switch to Off.

Overcharge (and we're not talking about the price tag)

I've done some experimenting with charging the iPhone and the battery seems to preform best when it's overcharged by about 25%. That means if it takes 2 hours to charge, then leave it on charge for 2.5 at least. The best way to do this is usually charging it overnight, when it will get a good long charge. 

Turn WiFi Off When Not Using It

Wifi is another power hungry service, and most people leave it running even when their out and about and using 3G services. So unless your using the WiFi turn it off. 

To turn WiFi off go to Settings > Wi-Fi and switch to Off. Same procedure to turn back On. You may need to spend an extra 5 seconds when you want to use WiFi to turn it back on but it will save a significant amount of battery life.

Turn Personal Hotspot Off When Not Using It

Same theory as WiFi applies to Personal Hotspot. It's another power drain and isn't really needed when your walking around the supermarket. 

To turn it off go to Settings > Personal Hotspot and switch to Off. Same procedure to turn back On.

Turn Siri Off

This is the big one. Siri swallows power like a Ferrari drinks petrol.

Unless you use Siri at least 2 - 3 times a day you can probably do without it, (entertaining yourself/friends by asking her silly questions doesn't count). Even more so outside US where Maps and Locations don't work. 

Siri is constantly indexing and sending information to Apple in order to help her help you, which drains power. Turning her off will help a HUGE amount.

To turn it off go to Services > General > Siri then turn it Off. You will get a whole load of warnings about your the information Siri uses being deleted from Apple's servers but this is nothing to worry about. None of your information will be lost on your phone or from iCloud etc is just Siri information that is deleted and if you ever turn it back on (when iOS 6 gets released for instance) then the information will be recompiled.

Using this tweaks, or at least a mixture of them, I've managed to increase my battery life from 15 - 20 minutes per % to 30 - 35 per %. Over a full charge this has worked out at lasting about 55 hours on a charge which average usage. That means a little gaming, text, emailing checking apps occasionally, and making a few phone calls. 


EDIT

In response to a recent article from Huffington Post that I read regarding Tech Myth's (linky here), where it said, from information based on an article form another source, that killing apps doesn't make a difference to battery life. The information presented by the Huffington Post in right for the most part, most apps don't drain battery life however as I stated killing apps does help as some will still drain power through Location Based services that they don't deactivate till they are killed. 





Friday, 29 June 2012

Automatic Reference Counting (ARC)

Automatic Reference Counting, otherwise known as ARC, is a feature implemented in Xcode 4.2+. In previous version programmers had to maintain memory management manually, ensuring they dismissed objects after they were finished using them.

As anyone with programming experience knowns this can be tiresome as miss an object and you can get memory management issues which can lead to no end of trouble. ARC handles all this for you.

When using ARC, enabled by default in any Xcode 4.2+ projects, as long as your implement the right code in your functions the complier will work out, and add the relevant code, for when objects should be dismissed.

ARC is incredibly easy to implement. If you have a function as follows:


//
//  NumGenViewController.m
//  NumGen
//
//  Created by James Krawczyk on 29/06/2012.
//  Copyright (c) 2012 James Krawczyk. All rights reserved.
//

- (IBAction)GenNum:(id)sender 

{
    int ran = 0;
    ran = arc4random() % 1000;
    numOut.text = [NSString stringWithFormat:@"Num: %i", ran];
}


All you have to do to implement ARC is add @autoreleasepool { and then a corresponding closing } at the end of the function, as so: 

//

//  NumGenViewController.m

//  NumGen

//

//  Created by James Krawczyk on 29/06/2012.

//  Copyright (c) 2012 James Krawczyk. All rights reserved.

//


- (IBAction)GenNum:(id)sender 



{

    @autoreleasepool 

    {

        int ran = 0;

        ran = arc4random() % 1000;
        numOut.text = [NSString stringWithFormat:@"Num: %i", ran];
    }
}

In order to use ARC effectively you need to add this to every function you create that will be using objects.

Thursday, 28 June 2012

NTFS Read/Write in OSX

I recently dug out my old Terabyte external drive which I used to use under Windows so was formatted in NTFS. Connected it up to my MacBook Pro, and annoyingly discovered OSX only supports read file permissions on NTFS by default.

There is, in newer versions of OSX, a built in read/write ability but it's disabled by default by due it being unstable to say the least. In just a short time searching I've found a number of reports of people using it and then getting a corrupted drive. Ironic really that Apple, after wanting Microsoft Office support on OSX, and building what is essentially one of the most user friendly unix/linux distributions out there, can't get basic support for what is a Windows file system.

Anyway, back on topic, there are a couple of methods you can use to make NTFS drives be both readable and writeable on OSX.

The one I'm going to recommend as it's the solution I use it Paragon NTFS. It's a simple program that is install and forget. Once installed just restart and any connected NTFS drive from there on out will be both readable and writeable. It is a commercial solution but at only £12.95 ($20) it's a worthwhile investment if you'll be using NTFS drives a lot.

The second solution is a free one but the software is no longer officially supported which means any problems won't get fixed. And there will be bugs. The solutions for implementing it I'm going copy and paste from www.ntfsonmac.com out of pure laziness.

From www.ntfsonmac.com


Step 1. Install FUSE for Mac OS X

FUSE for Mac OS X allows you to extend Mac OS X's native file handling capabilities via third-party file systems. OSXFUSE is a successor to MacFUSE, which has been used as a software building block by dozens of products, but is no longer being maintained. The latest version supports Snow Leopard and Lion.

Step 2. Install NTFS-3G

One bad news, NTFS-3G is no longer maintained. We have to install old version of NTFS-3G. Download here and install. Now restart the machine and attach a drive.

Tuesday, 26 June 2012

Xcode Random Number (iOS & OSX)

There seems to be a lot a different ways to generate random numbers in Xcode when programming for iOS and/or OSX and a lot of people using some very complex method, which although are sometimes required, are usually overkill.

The simplest way I've found is arc4random(). All it requires it online line of code as follows:

ran = arc4random() % 50;

The number you specify, 50 in this case, will be the upper limit of your generation -1. So when 50 is defined you will generate numbers between 0 and 49.

A sample program (for command line in OSX):


//
//  main.m
//
//  Created by James Krawczyk on 27/06/2012.
//  Copyright (c) 2012 James Krawczyk. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool 
    {
        //Define integer variable to store random number in and initalize it
        int ran = 0;
        
        //Create random number between 0 and 49
        ran = arc4random() % 50;
        
        //Print result to log
        NSLog(@"Random Number: %i",ran);
    
    }
    return 0;
}




Sunday, 24 June 2012

Problems with Content Filters and Site Blockers

Many companies, organisations and ISP's are implementing content filtering of some form of another these days, often blocking perfectly litigate sites.

In my opinion there is never an excuse for blocking access to sites at a public level. There can in cases be reason to do it in a work environment, for example, when the need to check Facebook updates is overruling the need to work but there is never an excuse to block access to sites at a ISP level, e.g. preventing access completely.

Even so, there is sometimes sites that are block for no good reason. For example I used to frequent a forum that had a section discussing but not linking to torrents which was blocked. In cases like these we can sometimes need a way to bypass these filters.

There are many ways to do this, for example, VPN's, and although that may be one of the best methods it's not necessarily possible as they are often expensive and sometimes you just don't have enough access to the system your using to install them.

If you do have the ability to install a VPN on your machine I can recommend HotSpot Shield to be a good free one. It does embed ads into the pages you view but these can be closed and it is free with (almost) full connection speed.

The easiest method I've discovered, which although may not be perfect, does the trick is to use Google Translate. Simply enter the URL of the site you want to visit in the translate box and, presuming it's an English site, set the From language to Russian and To language to English. This will ensure you don't get an error regarding Already In English.

If you need to download something from the site in question, like in the case of a well known Pirate Ship logo'd site, if the site uses subdomains for the downloads, for example downloading.example.com/download.exe you can often just paste this straight into the browser as in a lot of cases, although the protection blocks the main site it doesn't recognise subdomains.

Lastly and this is by far the easiest method, although also the most unreliable as it doesn't always works, it to just use the sites IP address. Because IP address change so often, some computer level blockers such as those in use at a office only block based on domain names so enter the IP will allow access.

For example, say www.google.com is blocked, you can just as easily access it via http://173.194.34.99 (Note: also good address for testing if your internet is broken or ISP is having an issue with their DNS). In order to get a sites IP, (this would need done in advance) on Windows, go to Start > Run > cmd and then type ping google.com the IP address that appears in the reply format is the sites IP. The same system works for Mac OSX and Linux , although on those systems it will ping indefinitely and you will have to press Control + C in order to stop the ping.

ThinkPoint Virus Removal


So you’ve clicked that email attachment and now when-ever you load your machine you get a blank screen with ThinkPoint logo and Normal Startup and Safe Startup options. Not to worry, this “virus” is not as hard to remove as it looks.
Essentially this virus falls into the group of “fake anti-virus” programs which are all the common these days. It installs itself, does a fake scan of your system then reports a variety of faults and constantly gives you pop-up to buy the fake software. ThinkPoint is slightly different in that once installed it will not let you into your system, instead only giving you the ThinkPoint startup page with a black background after logging in.
This guide is written for Windows Vista/7 (All Versions), however the same principles for removal apply to XP.
First press CTRL+ALT+DEL which will give you a page offering various options. Select Task Manager and you will be brought back to the ThinkPoint start-up page. Sometimes the Task Manager will start behind the ThinkPoint page so you might have to fiddle around a bit to drag it out so you can see at least most of it.
Once in Task Manger to the Process tab and find hotfix.exe (Publisher TPI), right click and Kill Process Tree).
Next step is to go to File > New (Run) in Task Manager which will give you a small box to enter a program to run into. Again it might appear behind the ThinkPoint page so some more fiddling may be required. In this box type “cmd” without quotes. This will launch a Command Prompt window, which to the non-techy may look daunting but really isn’t something to worry about.
Next we’re going to have to type in some commands. Unless your really interested don’t worry about what each command does but the final result will be to remove the hotfix.exe file that run ThinkPoint.
In the Command Prompt box enter the following, followed by enter after each line. In the line with YOUR-USENAME replace YOUR-USERNAME with your user name, e.g. the name that appears on the login box for your account, for example “James”.
cd..
cd Users/YOUR-USERNAME/AppData/Roaming
del hotfix.exe
After this is done restart your system. This can be done by pressing CTRL+ALT+DEL again and using the Red button in bottom right hand corner.
Once restart and logged back in you’ll be presented will just a black screen this time. Again CTRL+ALT+DEL then Task Manager and File > New (Run). This time type “explorer”. This should launch your usual desktop.
Now go online and download Malware Byte’s Anti-Malware. Found here.
Install, making sure to update after installation then run and do a Quick Scan. After completed (10 – 15 minutes on standard system), click Show Results and tick everything (or just leave ticked) and click Remove Selected. After it’s done reboot your system (you will be prompted to do so anyway).
Your now running clean again!