Archive by Author

iOS 5 Twitter Framework Integration

One of the new features in iOS 5 that will save you a lot of time is the Twitter integration.

The first thing you need to do is add the Twitter framework to your project.

Then include the Twitter header file in your header

#import Twitter/Twitter.h

Next you need to create a TWTweetComposeViewController and set the text/link/image that you want to share.

TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init ];
[tweetSheet setInitialText:@"Tweet Text"]];
 
[tweetSheet addImage:[UIImage imageNamed:@"yourimage"]];
 
[tweetSheet addURL:[NSURL URLWithString:@"http://www.jamie.co.za"]];
 
tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result) {
        [self dismissModalViewControllerAnimated:YES];
    };
 
[self presentModalViewController:tweetSheet animated:YES];

Thats all there is to it, simple and quick.

There is also a canSendTweet function you can call to detect if the user has a twitter account setup on the device. The completionHandler will be called once the tweet has been sent.

MicroSIM Cutter

MicroSim Cutter

The MicroSIM Cutter arrived today in preparation for my iPhone 4S which I ordered. I was a bit nervous at first, but it worked really well. It even came with 2 adapters so that you can still use your sim card in other devices.

You can pick them up on bidorbuy, or www.microsimcutter.com

 

 

 

Mobile Antivirus apps on scancomplete.com

A new mobile apps section has been added to scan complete for anti virus, spam & spyware apps. It covers Android, BlackBerry, Symbian and Windows Mobile.

The number of apps is still relatively small but more will be added in the future. A lot of the older invalid apps have also been removed from the site.

 

Cut the Rope for Android

Cut The Rope

Cut The Rope

The previously iOS-only game Cut the Rope is now available for Android.

There is a free version on GetJar, or a paid version on the Android Market

Cut the Rope is a physics based puzzle game. The basic idea is that there is a piece of candy tied to several pieces of rope which you must in the correct order, and at the right time to collect as many stars as possible. The end goal is to drop the candy into the green monsters (although could be a frog ?) mouth.

The iphone version can be downloaded from iTunes

The game was developed by ZeptoLab.

Simultaneous Gesture Recognizers

To recognize 2 gestures simultaneously, such as to enable panning and rotating at the same time, there is a method called gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: in the UIGestureRecognizerDelegate protocol. By default it returns NO so implement the method and return YES.

 

- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
 
    return YES;
 
}

Custom UINavigationBar

Since I’ve moved over to just doing mobile dev (iPhone/iOS specifically), I thought I’d start occasionally posting some Objective-C code snippets. Coming from a PHP background its been a bit of a learning curve.

This is a simple Category to create a custom UINavigationBar inorder to apply it to the entire app. I only needed to set a background image so its really simple.

 

UINavigationBarSilver.h

#import 
 
@interface UINavigationBar (UINavigationBarSilver)
 
@end
UINavigationBarSilver.m
#import "UINavigationBarSilver.h"
 
@implementation UINavigationBar (UINavigationBarSilver)
 
- (void)drawRect:(CGRect)rect {
	UIColor *color = [UIColor clearColor];
	UIImage *img	= [UIImage imageNamed: @"top_nav_bg.png"];
	[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
	self.tintColor = color;
}
 
@end

Leaked Gingerbread Rom (2.3.2) for the Samsung Galaxy S

A beta version of the 2.3 Gingerbread Rom for the Samsung Galaxy S was leaked yesterday. More info here

Download here

Android Market in South Africa

This is probably just a glitch, but I’m seeing paid apps in my market place, and they’re listed in Rands. Although is not showing up on other phones and I get an error when I try buy using Google Checkout.

I don’t  have MarketEnabler on.

Backup Mysql database to Amazon S3 using Python

I wrote this script to do nightly backups of a mysql database to an Amazon S3 account. It’s the first bit of python I’ve ever done so please excuse any obvious mistakes.

It uses the Amazon S3 Library for REST in Python by EricW@AWS, which you can download here

The script does a mysqldump, compresses it and sends it to the S3 account. the KEEP var is the number days worth of backups you want to keep. It will delete the backup file which matches (today – KEEP). Its not ideal but it works for me.

from datetime import date, timedelta
 
import subprocess, tarfile, os, S3
 
#Mysql
mysql_user = "{DB USER}"
mysql_pass = "{DB PASS}"
mysql_db = "{DB NAME}"
mysql_host = "{DB HOST}"
mysql_dump = "mysqldump"
 
#S3
AWS_ACCESS_KEY_ID = "{AWS_ACCESS_KEY_ID}"
AWS_SECRET_ACCESS_KEY = "{AWS_SECRET_ACCESS_KEY}"
 
BUCKET_NAME = "{BUCKET NAME}"
 
#path name, leave empty if not required
FOLDER = "mysql-backup/"
 
#number days worth of backups to keep
KEEP = 5
 
#Output
output_dir = "/tmp/"
output_file = "db-" + str(date.today()) + ".sql"
 
print "start mysqldump..."
 
subprocess.call( mysql_dump + " --user " + mysql_user + " --password=" + mysql_pass + " --add-locks --flush-privileges --add-drop-table --complete-insert --extended-insert --single-transaction --database " + mysql_db + " > " + output_dir + output_file, shell=True )
 
print "compressing " + output_file + "..."
 
tar_file = output_file + ".tar.gz"
 
tar = tarfile.open( output_dir + tar_file , "w|gz")
tar.add(output_dir + output_file)
tar.close()
 
tar_data = open( output_dir + tar_file , "rb").read()
 
print "uploading to S3..."
 
conn = S3.AWSAuthConnection( AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY )
 
response = conn.put( BUCKET_NAME, FOLDER + tar_file, S3.S3Object( tar_data ) )
 
if response.http_response.status == 200 :
 
	oldest_backup = "db-" + str( date.today() - timedelta(days=KEEP) ) + ".sql.tar.gz"
 
	response = conn.delete(BUCKET_NAME, FOLDER + oldest_backup)
 
else:
 
    #should probably send an email here
 
    print "Error : "+response.message
 
print "deleting temporary files..."
 
os.remove(output_dir + output_file)
os.remove(output_dir + tar_file)
 
print "complete"

Bricked Samsung Galaxy S

This guide applies to the Galaxy’s that Samsung so annoyingly decided to disable the 3 button recovery mode. If you have bricked your device but have managed to use the 3 button recovery before, this youtube video might help you. Otherwise, keep reading.

So the other day I decided I would flash my device instead of waiting for the official Android 2.2 release for Africa. Even though its already released in other countries, we obviously have to wait for Vodacom to put their branding crap all over it. This should have been a fairly simple procedure but half way through upgrading using Odin, everything just froze. I left it for a while then eventually unplugged it. When I tried to turn the phone back on all I got was the Phone-!-PC screen or Black screen of death.

If you watched the youtube video above you’ll see this normally shouldn’t be much of a problem, but as my phone falls into the no-3-button mode I was pretty screwed. After stressing out for a few minutes I headed over to the XDA forums and found this very, very useful post. It explains what to do in my situation and while it requires a bit of work, its worth it in the end. I highly recommend you go read it.

The post describes how to build a test jig which will force your phone into download mode. It also mentions places where you can buy the components needed, but obvisouly it’s not ideal for anyone from SA because you’re probably looking at at least a months delivery time. So this is what I did:

MicroUSB Plug

MicroUSB Plug

1. A microUSB plug
I came very close to cutting up my wall charger to get to the plug, but instead headed down the the Muizenburg craft market (the one every sunday). From there you can pick up a generic charger for virtually nothing (R25 – R30). It doesn’t matter what phone it’s for as long as it has a microUSB plug. I bought a wall charger & a car charger but the car charger didn’t have the 4th pin so I’d recommend a wall charger. Whats nice about these ones is that the microUSB plug is housed in a plastic casing that easily pops open. It’s much easier than having to slice away at the rubber ones.

300k Resistor, 1k Resistor, MicroUSB Plug

300k Resistor, 1k Resistor, MicroUSB Plug

2. Resistors (combined resistance of 301K)
I struggled to find these at first. The electronics shop closest to my house didn’t have them and all the bigger stores are way too far away and would require taking time away from my weekend. I decided to order off Rabtron because they had everything I needed. As the resistors are only like 16c, I ended up buying 10 x 100k resistors, 10 x 1k resistors and 10 x 300k resistors, just to full up the order a bit. The total was still only R4.60 which made paying R30 for delivery a bit painful.

I ended up going with 1 x 300k & 1 x 1k resistor. I soldered them together then soldered the ends to pin 4 & 5. I plugged it in and after about 3 seconds it kicked it into download mode. From there you can flash any firmware you want.