iOS – Check if wifi is being used

In an app I was making recently I wanted to check if the user was using a wifi connection. I used the method below to check and just checked whether it returned true or false.

- (BOOL)networkCheck{
 Reachability *currentReachability = [[Reachability reachabilityForInternetConnection] retain];
 NetworkStatus networkStatus = [currentReachability currentReachabilityStatus];
 [currentReachability release];
switch (networkStatus)
 {
 case NotReachable: {
 NSLog(@"Not connected");
 return false;
 break;
 }
 
case ReachableViaWWAN:{
 NSLog(@"Cellular Network");
 return false;
 break;
 }
 
case ReachableViaWiFi:{
 NSLog(@"Wifi");
 return true;
 break;
 }
 }
 
return false;
}

Upgrading iPhone apps to run full screen on iPhone 5

As you probably know already, the iPhone 5 is taller than the previous iPhone 4S and iPhone 4. When I first heard about the change is size my first thought was how long is it going to take to update all my apps to work on these devices.

Turns out that so far it hasn’t been hard at all. I have just had to create a new Default.png to cater for the iPhone 5 and the rest is done automatically.
The new default image is 640px wide and 1136px tall and needs to be called Default-568h@2x.png. 

One thing to be aware of is that as much as this process is very easy, it might not work for every single app as some apps have positions and layouts hard coded. The apps that have standard layouts without hard coded values tend to be the ones that benefit from this automatic upgrade.

Replace custom UITableViewCellAccessory-DisclosureIndicator on cell select

After my last post about creating a custom UITableViewCellAccessoryDisclosureIndicator, I found something else to post about.

I needed to replace my custom Disclosure Indicator with a selected state. I tried to replace the image with the help of an if statement

if(cell.selected){
}

This didn’t work! I then found a solution which was to used the highlightedImage property of the imageview. So my code now looks like this:

UIImageView* arrowView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"disclosureIndicator.png"]] autorelease];
arrowView.highlightedImage = [UIImage imageNamed:@"disclosureIndicatorSelected.png"];
cell.accessoryView = arrowView;

Change UITableViewCellAccessory-DisclosureIndicator colour

I needed to change the UITableViewCellAccessoryDisclosureIndicator to be white as I had a dark background and the the default grey colour didn’t show up very well.

The best way to do this is to create an image and add it to an image view and add that to the cell.accessoryView.

cell.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"disclosureIndicator.png"]] autorelease];

Joomla 2.5: Displaying subcategory articles in Category Blog menu item

I have recently been working on a Joomla website and wanted to do the simple task of displaying my articles in a specific category on a page on under each other, just like a standard blog view.

I chose to use the ‘Category Blog’ menu item which worked perfectly until I wanted to display subcategories too. Any article I put in a subcategory no longer displayed on the page.

After lots of search the net I found the answer. The articles were actually being shown but the top level category articles were shown then each of the subcategories. So my article in the subcategory was moved to the end of the list, and due to pagination I didn’t see it on the first page.

To fix this, in the menu item settings, on the right hand side, select the option ‘Blog Layout Options’ and change ‘Category Order’ to ‘No Order’. This will make sure that the categories aren’t ordered in anyway so all articles that come under the parent category will be displayed in the order you specify.

WordPress 3.4.1 upgrade stopped Media Library working

I recently upgraded one of my WordPress websites to version 3.4.1. As soon as I did this I started experiencing issues with my media library.

Whenever I uploaded an image to the library I would be hit with a 404 error. I also got the same when I tried inserting an image into a post.

I searched the net extensively and tried many possible fixes but none of them worked. I tried altering my .htacces file (http://wordpress.org/support/topic/file-upload-link-error-404), I tried re uploading my wp-admin and wp-includes folders. I made sure my permissions were correct for the uploads folder and also the wp-content folder. I switched to the WordPress TwentyEleven theme but still the same issue was there. I even created a new site on the same host and was experiencing the same issue so decided it was something to do with my host.

I contacted my hosting company and explained the problem to them and with a couple minutes they had rectified the issue. Apparently the mod_security module was causing the conflict. They disabled it and just like that my site was working again.

A lot of the blog posts I found while searching for this had said that it was something to do with mod_security but none of the things I added to the .htaccess file seemed to be effective. 

I hope this helps someone having the same I had.

ShareKit 0.2.1 Twitter not working

I added ShareKit to my project and got the following error:

Twitter Send Status Error: {"error":"Could not authenticate with OAuth.","request":"\/1\/statuses\/update.json"}

The following is how I fixed it:
Around line 54 you will see the following code:

self.authorizeURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/authorize"];
self.requestURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/request_token"];
self.accessURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"];

These need to be changed to https://api.twitter.com/oauth rather than https://twitter.com.

NGTabBarController for iOS

A custom TabBarController which can be positioned on the bottom, top, left or top. Utilizes iOS 5 Containment API if possible, but works on iOS 4 too. The TabBar is fully customizable with a tintColor or background image as well as the possibility to show/hide the item highlight and the possibility to change the text colors, have image-only tabBar items etc.
Download the source code here

NGColoredViewController *vc1 = [[NGColoredViewController alloc] initWithNibName:nil bundle:nil];
NGColoredViewController *vc2 = [[NGColoredViewController alloc] initWithNibName:nil bundle:nil];
NGColoredViewController *vc3 = [[NGColoredViewController alloc] initWithNibName:nil bundle:nil];
NGColoredViewController *vc4 = [[NGColoredViewController alloc] initWithNibName:nil bundle:nil];
NGColoredViewController *vc5 = [[NGColoredViewController alloc] initWithNibName:nil bundle:nil];
 
vc1.ng_tabBarItem = [NGTabBarItem itemWithTitle:@"Home" image:image1];
vc2.ng_tabBarItem = [NGTabBarItem itemWithTitle:@"Images" image:image2];
vc3.ng_tabBarItem = [NGTabBarItem itemWithTitle:@"Live" image:image3];
vc4.ng_tabBarItem = [NGTabBarItem itemWithTitle:@"Contact" image:image4];
vc5.ng_tabBarItem = [NGTabBarItem itemWithTitle:@"Settings" image:image5];
 
NSArray *viewController = [NSArray arrayWithObjects:vc1,vc2,vc3,vc4,vc5,nil];
 
NGTabBarController *tabBarController = [[NGTestTabBarController alloc] initWithDelegate:self];
 
tabBarController.animation = NGTabBarControllerAnimationMoveAndScale;
tabBarController.layoutStrategy = $isPhone() ? NGTabBarLayoutStrategyEvenlyDistributed : NGTabBarLayoutStrategyCentered;
tabBarController.itemPadding = 10.f;
tabBarController.showsItemHighlight = NO;
tabBarController.tintColor = [UIColor redColor];
tabBarController.viewControllers = viewController;
self.window.rootViewController = tabBarController;

NGTabBarController was created by Matthias Tretter (@myell0w).

iOS Launch Images

When creating a new universal IOS app you need to create a minimum of 6 launch images to support the iPhone and iPad (both including their retina displays).

For the iPhone you have it easy, only 2 are required.

Default.png – 320 x 480
Default@2x.png – 640 x 960 

For the iPad there are a few more:

Default-Portrait.png – 768 x 1004
Default-Portrait@2x.png – 1536 x 2008
Default-Landscape.png – 1024 x 748
Default-Landscape@2x.png – 2048 x 1496

You can specify images for Landscape Right and Left and also Portrait Upside Down using the names below:

Default-LandscapeLeft.png
Default-LandscapeRight.png
Default-PortraitUpsideDown.png

For more information on Custom images and icons visit the apple developer site