Building an iBeacon-based app

I spent a big chunk of my free time in the last couple of months to build an iOS app. The app’s primary feature is to connect with people who are in your close (close as in Bluetooth) range. Here’s what I’ve learned in the process.

Handling permissions – your users will see lots of dialogs

Running anything in the background in iOS is painful. From Apple’s point of view this is perfectly reasonable – they don’t want you to drain their devices’ precious battery. On the other hand the UX is terrible. You’ll only get one shot to convince your users to give you the desired permission. If they don’t do it then comes the “leave the app and change the settings” scenario. Instant churn.

The Location Services background permission is a special case. Apple will constantly ask the user in random intervals if they are aware that your app does location scans in the background. This can quickly lead your users to disable it as it was some kind of malware.

Then there are some badly worded system dialogs – my favorite is the “Turn on Bluetooth” dialog which has two buttons: OK and Settings. You’d assume that the OK button would turn on Bluetooth but it just closes the dialog. It’s really nice since users generally don’t read these at all, just bluntly hit OK and expect the problem to go away.

The background settings are brittle at best. There’s an app level permission, and there’s a permission for the whole system (parental lock excluded). It again makes sense from the user’s side, but from the app’s side it’s disastrous. The API calls will just return that there’s no required permission to run, but they won’t tell you why. It’s quite hard to guide the user through the problem if you don’t know the cause.

BLE is special

In a bad way. First there’s no way to tell if the device Bluetooth is turned off, or is not supported at all (aka iPhone 4). Now I lied, you can deduce this with checking various constants, but if you’d like to do this cleanly using the API you’re doomed.

Then there’s the plist fun when you need to add the keys to support background Bluetooth running. You can also have a lot of fun with events not firing, or firing with a huge (40 secs) of latency. In a real time app like mine, this is a huge deal.

Broadcasting iBeacons in the background – confusion overload

The short answer is that it’s impossible. You will only be able to broadcast iBeacons when your app is in the foreground. The problem is that there are tons of resources (mostly stackoverflow users in despair) who claim otherwise or offer creative ways around the problem. But nothing works. What works is a UX which rewards the user for opening and engaging with the app. Forget everything else.

Background Bluetooth scanning – even more confusion

Ranging or geofencing (region entering and leaving)? What constitutes a region? What can I do in the background?

I was really confused at first. Region entering can run in the background, but with a limited set of regions (I remember 20 for the whole device). Ranging cannot run when you’re in the background. The problem is when you use iBeacons you’d like to identify them (major/minor anyone?). Region entering won’t do this for you, you’ll need ranging.

But a little creativity goes a long way. Entering a region will wake up your app and you’ll have 5 seconds to do what you need. Now you can use these 5 seconds for ranging, since you’re not in the background anymore. Problem solved.

So what’s the conclusion?

If I were to start again this app I’d do it on Android. I finished it because the emotional investment was huge. On iOS you’d get seriously hindered functionality when you try to be creative with iBeacons. They seem to be a perfect fit for indoor navigation but when you try to do something different you’d hit into way too much barriers.

Oh, the app is waiting for review right now. I’m very interested to see if Apple approves it. I’ll post about it when it’s done.


iPhone app – tomorrow

Well, the time has come to publish my company’s first iPhone application. It is intended to be an exploration (rather than a big hit). I’ve worked a couple of days with it, and my designer colleague did a good job in these days, so we’ll send the app for a review to Apple, and then wait anxiously for the results.

This is the first reason I stopped publishing learning materials for MCP exams. The second reason is that I must study for my university exams (which is a very painful thing to do). The last is that I’m working ten hours a day in the family business, we are in the middle of a big project. But the posts will continue, as soon as I finished my semester (or maybe before that, I’d love to start learning WCF…).

But back to the app. From a programmatically point of view, this wasn’t a big challenge, just a quiz with some nice features, such as Facebook integration and communication with a .NET web application, via SOAP (I couldn’t restrict myself). The hard part was Objective-C and the Cocoa Framework. I worked (and studied) with .NET for so long that I tried to solve every problem in the .NET way, tried to follow best practices, etc. But Objective-C is much closer to C++ than it is to C#, so I have a great time allocating, initializing and releasing objects. Also, I had troubles with the exception-handling (especially the information provided) in .NET, but in Objective-C, that was a nightmare. App crashes with EXEC_BAD_ACCESS, and nothing else, give me moments of pleasure. But this the result of my own inexperience and lack of knowledge, nothing else. So I came up with the idea to learn something lower level than the .NET Framework, maybe C. That would help me a lot I think.

Except these issues, it was a pleasure to program against the iPhone, and I’m quite sure  that this wasn’t the last time (there will be apps until the price of the Mac comes back, or I’ll be killed, I suppose). I’ll let you know when Apple approves the application.

Consuming a .NET Web Service from iPhone

This was something which take me a whole (working) day to implement, and I’d like to share the new-found knowledge with everybody interested. We’ll use SOAP with a simple .asmx web service (for the sake of simplicity). I’ll only focus on setting up the connection, so tasks such as authentication and security are to be implemented by you.

First, we’ll need the service. Our simple little web service will return void, and take two parameters, a user name and an integer value representing the user’s score (yes it’s a high score table). The service will take care of putting these values into a database. The SQL table looks like this:

ID Primary key, Identity seed (1,1)
Name nvarchar(50)
Score Int

Continue reading

Blog Still Operating

Hello Everybody! Sorry for the lack of posts, currently I’m spending all my time working on my shiny new iPhone application. If things go this fast (and Apple approves my company and the application) the app will be out in two weeks. I hope people will like it, I put much work into it.

Now a little about Objective C. I like it, and getting fond of it. Poor Visual Studio is being neglected on my computers, XCode rules (for now). However, I’m quite sure I won’t change platform for good.

As I have no background (to be honest, I have a minimal background) in C or C++, I’m using Objective C to get a deeper understanding in them. I fell in love with the memory-management questions and techniques. It’s such an interesting topic, and the .NET Framework wants to do it all instead of you.

But I haven’t forgotten my goal to become an MCPD, I just take a quick refreshing excursion, so be prepared to more post of 70-536, particularly about security and reflection. Happy coding till then!

iPhone App on the Horizon

Now I’m a bit stuck in my .NET studies (I’m slowly getting unmotivated because the 70-536 exam seems to focus on method overloads and constructors), so I decided to play around with iPhone development and Objective-C a little. I’ll recently publish my first app, it’ll be a quiz application, just to get the flavor of it.

The goal is to publish some really eye-catching apps, but first I’ll need to train myself into the Cocoa Framework, and then find (or train) a graphic expert for my company.

The point is, for a little time, .NET notes will be suspended. I think I’ll post some iPhone-related articles during this period, but I’ve just started studying the language, so I’m not very confident in it, and don’t want to mislead anybody with my possible errors.