Adding your iOS App’s Build Number to UIWebView Content [#UIWebView, #iOSDev]

Recently I needed to automate the retrieval of the build number for the app I am currently developing, and instead of including the build number in a standard UI component like a UILabel, I needed to add it dynamically to some HTML that was being used as an About Us view.

The solution was pretty simple, but I thought I’d share it anyway since it was fun.

The first thing to do is edit the HTML, so at the place I needed to insert the build number, I simply added a rudimentary replaceable tag to the body of the HTML:

<p>Build: [BUILD_NUMBER]<p>

The next step was to add a method (though I could have also done this inline) to replace the tag with the build number, using [[[NSBundle mainBundle] infoDictionary] objectForKey:@”CFBundleVersion”] to retrieve the build number:

- (NSString *)insertBuildNumber:(NSString *)htmlContent {
    NSString *buildNumber = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
    htmlContent = [htmlContent stringByReplacingOccurrencesOfString:@"[BUILD_NUMBER]" withString:buildNumber];
    return htmlContent;

Then, we put it all together in the method I was using to load the HTML. In this case I was just using ViewWillAppear.

- (void)viewWillAppear:(BOOL)animated {
    // get the file path
    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"about_us" ofType:@"html"];
    // get the file content
    NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
    // replace the tag with the build number
    htmlString = [self insertBuildNumber:htmlString];
    NSString *basePath = [[NSBundle mainBundle] bundlePath];
    // load the HTML into the UIWebView
    [self.webView loadHTMLString:htmlString baseURL:[NSURL fileURLWithPath:basePath]];

The final result worked great and now I can show the build number in the app as it gets updated via the Archive process (I have a separate script for that).

iFunBox Recovers PhotoStream Photos [@ifunbox_dev, #PhotoStream, #iOSDev]

After the announcement of iOS 8, I realized that I had an old iPhone 4 lying around, and locked away inside that device were some photos that I had a feeling were on the device, but not in the PhotoStream for the associated iCloud account. So the next question was… how do I get at those photos? Is it even possible?

Then I remembered that a former coworker had recommended a utility called iFunBox (Twitter: @ifunbox_dev) and it seemed like it might be the right tool for the job.

Turns out it worked very well. I was able to use iFunBox (awful name, sorry guys.) to navigate through the file system and find the PhotoStream files and save them!

iBeacon Compatible Apple Devices

I was doing a little research to see if I could use my retired iPhone 4 as an iBeacon test device for either advertising or detecting, and unfortunately the answer is no.

Here is the list of Apple devices that officially support iBeacon, taken from the Apple KB article iOS: Understanding iBeacon (KB: HT6048):

To use iBeacon, you need iOS 7 or later, Bluetooth turned on, and a compatible iOS device:

  • iPhone 4s or later
  • iPad (3rd generation) or later
  • iPad mini or later
  • iPod touch (5th generation) or later

I was a little disappointed, but not really surprised. The iPhone 4 can barely run iOS 7, so it’s usefulness is rapidly declining, especially on the eve of WWDC 2014 (literally!)…