“Warning: Attempt to present on while a presentation is in progress!”

“Warning: Attempt to present <CDVInAppBrowserViewController: 0x1ed97060> on <MainViewController: 0x1ed64730> while a presentation is in progress!”
I was getting this issue when i opened an InAppBrowser on an iOS device. When this happened the InAppBrowser would not actually load.

The solution to this is to wrap the window.open call in a setTimeout

setTimeout( function() { 
     var ref = window.open("http://www.google.co.uk","_blank","location=no");
}, 500);

This is only required for iOS as for some reason it needs some extra time before starting the InAppBrowser.
One other thing to note is that any event listeners you have on ref will need to go in the timeout or you will be trying to bind and event listener to nothing.

Undefined symbols for architecture i386 – Reachability

Today I add the Reachability classes to an app I am working on, added my #import Reachability.h to the correct files and then implemented a method to check if the device was using wifi.

When I hit build, I got the following error.

Undefined symbols for architecture i386:
"_SCNetworkReachabilityCreateWithAddress", referenced from:
+[Reachability reachabilityWithAddress:] in Reachability.o
"_SCNetworkReachabilityCreateWithName", referenced from:
+[Reachability reachabilityWithHostName:] in Reachability.o
"_SCNetworkReachabilityGetFlags", referenced from:
-[Reachability connectionRequired] in Reachability.o
-[Reachability currentReachabilityStatus] in Reachability.o
"_SCNetworkReachabilityScheduleWithRunLoop", referenced from:
-[Reachability startNotifier] in Reachability.o
"_SCNetworkReachabilitySetCallback", referenced from:
-[Reachability startNotifier] in Reachability.o
"_SCNetworkReachabilityUnscheduleFromRunLoop", referenced from:
-[Reachability stopNotifier] in Reachability.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)


I figured it was a framework that I had forgotten to add to I added the CFNetwork.framework and hit build again, same error again. I then added SystemConfiguration.framework into the project and hit build, and success!!

It was such a simple fix but the errors that were displayed weren’t really helpful with explaining what framework needed to be added.

Push Notifications for iOS Apps – PushWoosh

I came across a service for push notifications, probably a bit late to the table but I have only just needed push notifications in my apps.

Being a web developer my original idea was to host the service on my hosting and then that way I would be able to send as many notifications as I wanted without having to worry about any extra costs etc.
This seemed to be more problematic than planned as I had to have ssl and specific ports opened and my hosting is a shared hosting which means that its a bit harder to get this all implemented.

I did some research and found a number of online services that offered push notification but the one that I went with was http://www.pushwoosh.com as they offered the best free package. You get unlimited notifications and up to 10 applications. Other services like http://www.parse.com.

Push Woosh was perfect for me as I just needed bog-standard notifications and it was also pretty easy to implement too.

Using Current location in Apple Maps

I was updating one of my iOS apps that used to open up the Maps Application to show directions from the current location to a set of coordinates.

Before Apple Maps was introduced we could use “Current Location” as a way for Maps to use the users current location (http://maps.google.com/maps?saddr=Current%%20Location&daddr=51.535455,-0.247557) this no longer works in Apple Maps.

To get round this problem I had to use CLLocationManager to get the current location and then use that in the URL.
Start off by adding the CoreLocation framework.


@interface MapViewController : UIViewController<MKMapViewDelegate, CLLocationManagerDelegate>{
CLLocationManager *locationManager;


locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    NSLog(@"didUpdateToLocation: %@", newLocation);
    currentLocation = newLocation;
    [locationManager stopUpdatingLocation]; //Added to prevent continuous updating as we only needed the location once.
-(IBAction) viewinMaps {
    Class itemClass = [MKMapItem class];
    if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) {
        // iOS 6 MKMapItem available
        NSString *locationQuery = [NSString stringWithFormat:@"http://maps.apple.com/maps?saddr=%f,%f&daddr=51.535455,-0.247557", currentLocation.coordinate.latitude, currentLocation.coordinate.longitude];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:locationQuery]];
    } else {
// pre-iOS 6
        NSString *locationQuery = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=Current%%20Location&daddr=51.535455,-0.247557"];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:locationQuery]];

Add a custom font to iOS app

I recently needed to add a custom font to my iOS app as the standard ones didn’t work for what I wanted.

I downloaded a .ttf file, (I used www.dafont.com) and copied it into my Xcode project.
The next step is to open your project’s Info.plist and add a new key “Fonts provided by application” and ensure its an array. In the first object of the array add the value “<fontname>.<fileextension>“. So where I used the font digitalism the value I entered was “digitalism.ttf

To then use this font on a label its just the same as any other font:

[myLabel setFont:[UIFont fontWithName:@"digitalism" size:20]];

purgeIdleCellConnections: found one to purge conn iOS error

I received this error when I plugged my iPhone 5/iOS 6.1.2: purgeIdleCellConnections: found one to purge conn

I did a quick google search for this and found that there was a lot of people that had the same issue.
One of the results I found was from a Technical Q/A on the Apple Developer iOS site:

purgeIdleCellConnections Log Message

Q:  While testing my app on iOS 6.0 I noticed the log message purgeIdleCellConnections: found one to purge. What does that mean?

A: This is a debug message that’s been erroneously left enabled (r. 12431060) . It happens during the normal operation of any app that uses NSURLConnection and does not, in itself, indicate a failure. The rest of this document explains what it actually means.

Internally NSURLConnection maintains an HTTP 1.1 persistent connection cache. Each cache entry represents a set of persistent connections to a host. When a new request comes in, it is queued on an entry in the cache. This may be an existing entry or it may be a new entry, and it may also generate a new HTTP connection within that entry, depending on various complex factors (the protection space, the authentication status when dealing with authenticated connections like NTLM, pipelining, various cache limits, and so on). When a connection associated with a cache entry finishes running all of its requests, it looks for more work on the cache entry’s queue; if it doesn’t find any, it goes idle. If a connection is idle for too long, it is purged, which closes the underlying TCP connection.

This cache implementation has changed in iOS 6. Prior to iOS 6 there was a single mechanism for purging idle cache entries, with radically different timeouts for OS X and iOS (30 seconds versus 6 seconds, and the iOS value could be as low as 3 seconds on older versions of iOS). In iOS 6 there are now two mechanisms for purging idle cache entries, one that applies to connections running over the WWAN and one that applies to all other connections. The WWAN timeout has dropped back to its old value (3 seconds) while the all-other-connections timeout has been bumped up to the OS X default (30 seconds).

The log message you’re seeing is generated when a WWAN connection is purged. This log message didn’t exist in iOS 5.x, which explains why you’ve just started seeing it. However the basic mechanism has been present, in one form or another, on all versions of iOS.


UILabel blurry on some views

I recently noticed that in one of my apps I’m working on, some of the UILabels I was using were blurry. This was only obvious on non-retina devices.

After a bit of research I found that it was down to using floating numbers to define the frame of the label. Basically, floating numbers use decimals and sometimes did not line up with the onscreen pixels. The solution was to force the frame to use integer numbers instead of floats.

[lmyLabel setFrame:CGRectIntegral(myLabel.frame)];

You would be able to cast all of the frame values to integers but using CGRectIntegral will do the work for you.

Git pull and push asks for username and password every time

I recently rebuilt my computer and cloned a git repository that I had been working on. Once I started working on the project again, I realised that every time I was executing a pull or push command in git bash it would ask me for my username and password whereas before it used to only request by password.

I checked my .gitconfig and it contained the correct details (under [user] i had name and email). I double checked that a second .gitconfig hadn’t been created elsewhere that was causing a conflict.

I eventually found out that it was because I had cloned the repository using the https url instead of the ssh. I just had to change the way I was connecting the remote repository, and that was done using the command below. Once I had done this my push and pull commands no longer asked for my username.

git remote set-url origin git@github.com:username/repo.git

Can’t access specific website on Mac

I recently encountered a problem with a website I was working on. I stopped being able to access the site. All my browsers were not able to connect to the server. I was able to access all other sites that I needed.

I contacted the host of the website and requested that they check my ip address had not been blocked on their end which they did and it didn’t help.
They suggested I check my ISP. I then tried to access the site using my mobile phone on the same wifi network and this worked fine.

After some time I realised I had set up a server using MAMP Pro using the same address as the site which I had forgotten about. This was stopping me accessing the site. Once I changed the name of the server I set up, I was able to access the site without any problems.

iOS Navigation Bar behind status bar after closing full screen MPMoviePlayer

I had a problem with an iOS app I am creating. I have a view that has a UINavigationBar at the top and a table view  that displays a full screen video on didselectrowatindexpath. Once the video is playing if the device is rotated and the done button is pressed the video will disappear but the navigation bar has moved to the top of the screen displaying behind the status bar. This leaves a gap between the nav bar and the top of the table view.


I tried a number of things to fix it including setting the status bar to hidden and then not hidden once video had exited full screen. I also tried the same with the navigation bar.

The fix that actually worked in the end did follow these lines. I added observers to MPMoviePlayer notifications and hid the nav bar when the video entered full screen mode. Once the video exited full screen mode I showed the nav bar again.

Below are how you add the observers that are required. I placed them in the viewDidLoad method.

[[NSNotificationCenter defaultCenter] addObserver:self
[[NSNotificationCenter defaultCenter] addObserver:self

I then created the methods to hide and show the navigation bar. These methods can include any other UI updates you might need to do such as refreshing a table view.

    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [self.navigationController setNavigationBarHidden:NO animated:NO];

After creating these the Navigation bar behaved as expected and no longer displayed behind the status bar.
There is still one more step to the process and that is removing the observers to the notifications. I added these to the dealloc method

[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidEnterFullscreenNotification object:nil];