Earlier this month, I uninstalled Facebook from my phone. I also made a commitment to own my own content and to share shorter notes on my site. Since then, I shared my POSSE plan and I already posted several shorter notes.

One thing that I like about Facebook and Twitter is how easy it is to share quick updates, especially from my phone. If I'm going to be serious about POSSE, having a good iOS application that removes friction from the publishing process is important.

I always wanted to learn some iOS development, so I decided to jump in and start building a basic iOS application to post notes and photos directly to my site. I've already made some progress; so far my iOS application shares the state of my phone battery at https://dri.es/status. This is what it looks like:

My phone's battery level is 78% and it is unplugged

This was inspired by Aaron Parecki, who not only tracks his phone battery but also tracks his sleep, his health patterns and his diet. Talk about owning your own data and liking tacos!

Sharing the state of my phone's battery might sound silly but it's a first step towards being able to publish notes and photos from my phone. To post the state of my phone's battery on my Drupal site, my iOS application reads my battery status, wraps it in a JSON object and sends it to a new REST endpoint on my Drupal site. It took less than 100 lines of code to accomplish this. More importantly, it uses the same web services approach as posting notes and photos will.

In an unexpected turn of events (yes, unnecessary scope creep), I decided it would be neat to keep my status page up-to-date with real-time battery information. In good tradition, the scope creep ended up consuming most of my time. Sending periodic battery updates turned out to be difficult because when a user is not actively using an iOS application, iOS suspends the application. This means that the applications can't listen to battery events nor send data using web services. This makes sense: suspending the application helps improve battery life, and allows iOS to devote more system resources to the active application in the foreground.

The old Linux hacker in me wasn't going to be stopped though; I wanted my application to keep sending regular updates, even when it's not the active application. It turns out iOS makes a few exceptions and allows certain categories of applications – navigation, music and VOIP applications – to keep running in the background. For example, Waze continues to provide navigation instructions and Spotify will play music even when they are not the active application running in the foreground.

You guessed it; the solution was to turn my note-posting-turned-battery application into a navigation application. This requires the application to listen to location update events from my phone's GPS. Doing so prevents the application from being suspended. As a bonus, I can use my location information for future use cases such as geotagging posts.

This navigation hack works really well, but the bad news is that my application drains my phone battery rather quickly. The good news is that I can easily instruct Drupal to send me email notifications to remind me to charge my phone.

Scope creep aside, it's been fun to work with Drupal 8's built-in REST API and to learn some iOS application development. Now I can post my phone's battery on my site, posting notes or photos shouldn't be much more difficult. I'm guessing that a "minimum viable implementation" will require no more than another 100 lines of code and four hours of my time. My current thinking is to go ahead with that so I can start posting from my phone. That gives me more time to evaluate if I want to use the Micropub standard (probably) and the Indigenous iOS application (depends) instead of building and maintaining my own.


Ryan (not verified):

Too funny. And here I was thinking I was doing good to update my site's security releases yesterday. : P

Did you write a custom module for the read time indicator on this post, or is that coming from a word counting contrib?


Yes, I wrote a custom read time indicator. I'll try to share the code later this week.

Matt Glaman (not verified):

How was the learning curve for native iOS? Was it with Swift or Objective-C?

I'm considering the mobile app approach. But I may just do a ReactJS Frontend with a service worker. So instead of a full native app it is just a decoupled admin. But I also considered geotagging - like DrupalCon - and if this would be viable.

I'm on Android, and my attempts at writing a native app have led to fruitless frustration.

I might try React Native. I'd like to be able to share the code as an example.

joshua.boltz (not verified):

I'm assuming the time it took Dries to get running with this project it was Swift. Swift has a much more developer-friendly JavaScript-like syntax, whereas Objective-C is more, uh, C-like. I think most web developers are more accustomed to working with Javascript than C, so the learning curve is probably a lot less with Swift. It's pretty crazy what he had to go to get the "running in the background" functionality. I would think you could just enable background mode to get it working without all that extra mapping stuff.
Curious - what caching rules do you have so that Drupal doesn't cache the percentage number and when it updates on your phone and sends to Drupal via REST, Drupal shows the correct percentage number?


My iOS application is currently written in Swift 4. I found it to be pretty straightforward, though I don't think I'll ever get used to Swift's Closures. ;-) I might try to rewrite the application in React later. It would be educational to compare and contrast both approaches.

Pasqualle (not verified):

The old Linux hacker is still satisfied with the limitations of his phone? I would recommend to start the "own my phone" movement also, to fully understand how apps and websites should be built in the mobile world.

Anonymous (not verified):

It's interesting that somebody so keen on security like you is willingly sharing his behavioral patterns with all the universe.

Eddie Hinkle (not verified):

Hey Dries, it’s great to see how your workflow is progressing! I'm the maker of Indigenous. I think it's great you are building your own app to publish to your site (battery status included πŸ˜‰) and learn iOS development.

My hope for Indigenous is for it to be a wide ranging support for lots of different people and their needs. Because of that, if you have any specific things that are important for you in a posting app, I'd love to hear it!

(Originally posted at https://eddiehinkle.com/2018/02/26/17/reply/ using Indigenous πŸ˜‰)


Thanks for your comment, Eddie. I'll let you know my thoughts after I had a chance to take a closer look at Indigenous.

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.