iOS/iPhone/iPad

A Maker Review on Bluetooth Smart Beacons (or Apple iBeacons)

A Maker Review on Bluetooth Smart Beacons (or Apple iBeacons)

Lately, but not for very long (as of the writing of this article), there has been a bit of buzzy-buzzy around Apple's iBeacon technology. It's a mixture of software and hardware that allows iOS devices to receive one-way broadcasts from little Bluetooth "beacon" devices. It was touted to be the big "NFC killer" (NFC = Near Field Communications). I would add an asterisk to that statement: It's an NFC killer as far as retail and point-of-purchase, but probably not as far as supply chain (container tracking), security (door fobs, badges) and other non-retail uses. Edit: Apple does now include NFC on the iPhone 6 and 6+ and utilizes NFC in their Apple Pay system.

I didn't think much about the technology at first. "NFC killer" seemed like a pretty bold statement. How can you beat the simplicity of just touching your phone to a thingie at the point-of-purchase ("PoP")? It's basically "tap-to-buy." However, after some thought and discussions with business development peeps at the office, the possibilities beyond PoP started to become obvious. I started to realize just how flippin' cool this unassuming technology really was. Lemme 'splain...

Objective-C/iOS/iPhone: UIColor from NSString

Until I find a home for my little snippets of code, here is where they will go. While building an iOS (iPhone) application, I needed a quick little method in Objective-c that would take strings of color codes from data provided by web developer peeps and convert those string values into UIColor objects. For instance, sometimes we'd get "#ff7401" from the data for our app. Sometimes it might be formatted like, "0xff7401" or even just, "ff7401". I simply created a category on NSString to make is super-simple.

NSString+meltutils.h

[code lang="objc"]

//  UIColor+meltutils.h

//  Created by Andy Frey on 10/15/10.

#import <Foundation/Foundation.h>

@interface NSString (meltutils)

- (UIColor *)toUIColor;

@end

[/code]

NSString+meltutils.m

[code lang="objc"]

#import "NSString+meltutils.h"

@implementation NSString (meltutils)

- (UIColor *)toUIColor {

unsigned int c;

if ([self characterAtIndex:0] == '#') {

[[NSScanner scannerWithString:[self substringFromIndex:1]] scanHexInt:&c];

} else {

[[NSScanner scannerWithString:self] scanHexInt:&c];

}

return [UIColor colorWithRed:((c & 0xff0000) >> 16)/255.0 green:((c & 0xff00) >> 8)/255.0 blue:(c & 0xff)/255.0 alpha:1.0];

}

@end

[/code]

So, to use this, all you have to do is import the header file and send a message to your string that contains the color code:

[code lang="objc"] #import "NSString+meltutils.h" ... UIColor *c = [@"#ff840a" toUIColor]; ... [/code]

Hope that helps someone out a little!