Writing on Tablets Tech stuff from @yeltzland

Building an iMessage app

Now that iOS10 is out I thought it was about time I built an iMessage app for Count The Days Left.

To be honest, it took very little time once I’d written a script to generate all the “progress images” I needed i.e. 100 images that show the percentage completed in the progress bar.

The UI is just a standard Storyboard + UIViewController for layout, and then hooking up an event handler to a ‘Send Message’ button (see below for details).

    @IBAction func sendMessageTouchUp(sender: AnyObject) {
        if let conversation = self.activeConversation {
            let now: NSDate = NSDate()
            let model: DaysLeftModel = DaysLeftModel()
            
             // Make a new layout object
            let layout = MSMessageTemplateLayout()

            // Set the caption on the layout
            layout.caption = model.FullDescription(now)
            
            // Set the correct image on the layout
            let percentageDone: Float = (Float(model.DaysGone(now)) * 100.0) / Float(model.DaysLength)
            let intPercentageDone: Int = Int(percentageDone)            
            let imageName = String(format: "progress%d", intPercentageDone)
            layout.image = UIImage(imageLiteral:imageName)
            
            // Make a new message and set its' layout
            let message = MSMessage()
            message.layout = layout
            
            // Insert the message into the conversation
            conversation.insertMessage(message, completionHandler: { (error: NSError?) in
                print(error)
            })
        }
    }

Other than the usual fun with making everything look OK with Storyboards and Auto Layout at the different screen sizes, it all worked out pretty well as you can see from the screenshot below:

Count The Days left iMessage app screenshot

I’m not sure how useful this will be, but it was very easy to build and I’m pleased with the result.

Count The Days Left Apps iMessage

Getting Ready For iOS 10 Widgets

It’s summer, which means updating all the Brave Location apps for the new version of iOS.

Thankfully this year the UI changes weren’t too big, and the real work was because of how the Today widgets are changed in iOS 10.

In iOS 9, the widgets are on a dark background, so it makes sense for the text to be generally white. Here’s how my stunning well-designed widgets look in the Today section on my iPad running iOS9 …

iOS9 Today widget

Now in iOS 10, the widgets are much more accessible - can be accessed directly by right swiping even on the lock screen - but the design has also fundamentally changed. The background is now a light, semi-transparent color by default, on which obviously the white text of the existing widget design is basically unreadable.

Now I didn’t want to have an iOS10 only release ready, as all of my apps currently target iOS 9.0 and above and I want to keep it that way for a while.

So what I do at runtime is detect whether we are iOS 10.0 or above by the following code snippet:

let ios10AndAbove:Bool = NSProcessInfo.processInfo().isOperatingSystemAtLeastVersion( NSOperatingSystemVersion(majorVersion: 10, minorVersion: 0, patchVersion: 0) )

I can then set the background and text colors of the widgets to appropriate for iOS 10 when necessary, buy keep the “traditional” look and feel on what will soon be legacy versions.

Quite happy with the way it’s turned out, even though I say it myself.

iOS10 Today widget

Updates are should all be in the App Store shortly (in case anyone else is running the iOS10 beta), and for everyone else in September I assume!

Apps Daily Optimiser Count The Days Left Yeltzland

Taken Down by Microsoft Lawyers

So my “Bing Translate” Chrome extension got taken down by Microsoft lawyers.

It was actually quite popular (the last number of weekly users data I have was 9924), and just did one thing pretty well - you could highlight some text in Chrome, and the extension sent it to the Bing/Microsoft translation service and translated it into English.

It was in no way pretending to come from Microsoft or Bing - despite the fact that I was actually working there when I wrote it - but I suspect an automated search by Microsoft lawyers found the word “Bing” in the title and sent a takedown request to Google, who quickly took it down.

Now I changed the title and text to make no mention of Bing, and resubmitted to the Chrome Web Store, but it didn’t pass and is still not available.

I guess I could start a new extension and maybe work around it, but to be honest I can’t be bothered starting a fight with the Microsoft lawyers.

This is a real shame - not for me as I truly don’t care especially now I hardly use Chrome - but for all those users who clearly found it useful.

I can’t find a similar extension in the store - especially any sign of an official one from Microsoft - so it’s tough for the users and Microsoft missing out on the small about of traffic they were getting to help improve their translation service.

Really glad I don’t work for a lawyer-driven company any more!

Microsoft Bing Translate

More Reliable Background Notifications

I’m really happy with the “Show the days left as a counter on the app’s badge” feature on Count The Days Left, but unfortunately due to the way Apple implements background fetches makes it a little unreliable in staying up to date.

The latest version of the app fixes this by using push notifications to regularly wake the app to update itself.

Background fetch is unreliable

The problem was that I was using the background fetch feature to run the app in the background every so often, and when it runs update the number of days left on the badge.

However, the frequency the background fetches are run is completely down to the operating system. Now as far as I understand, iOS will allocate background processing time based on how often the app is used.

Obviously this causes a bit of a logical error. If the user enables the badge to show the number of days left, they are a lot less likely to open the app - which obviously means it’s less likely to run in the background, so is more likely to be wrong :(

Push notifications solve the problem

The best way of fixing this issue is to send out regular push notifications to the app, so it’s guaranteed to wake up and refresh the badge count.

In an earlier post I wrote about how I’ve found Azure the easiest way to set up the server side of things, and I did the same here.

I then send out notification with "content_available": 1 in the payload, which will not show anything in the Notification Center to the user, but the app will wake up in the background and run the code to update the app.

Obviously this means setting up some (minimal) server infrastructure to manage this. I’ve written a NodeJS script that triggers the push notification via the Azure API, and setup a cron job to run the script every 6 hours.

So far for me this has worked a treat, and I’m much happier with the solution even though it took a bit more work.

The new version of the app (v2.0.4) is available on the App Store right now.

Apps Swift Count The Days Left

Android vs. iOS Development

I’ve recent just shipped the same pretty simple app on both Android and iOS, so I thought it would be interesting to capture my current feelings on what is nice - and not so nice - about developing for each platform.

Big Caveat

I’m a lot more experienced building for iOS than for Android, so I’m almost certainly biased towards Apple. Don’t hate me.

Android Good Points

Release Process

Now Apple is getting much better at reviewing apps - my last few releases have all been out in less than 2 days - but it’s really nice to be in full control on when I can push out a new version.

The Google Play developer web site is also more comprehensive than iTunes Connect.

Image Generation

I love the image generation tool in Android Studio, which lets you generate all the image sizes you need for different screens resolutions from one original source.

I also love you can easily generate images from text, which was perfect for use make Font Awesome based icons.

iOS Good Points

Layout

I truly don’t understand exactly how all the different layout options work (LinearLayout, RelativeLayout etc.) Also the visual editor in Android Studio didn’t work well for me, so I ended up working in XML most of the time. That wasn’t fun.

It may be because I’m used to it, but the “storyboards plus constraints” way of laying out UI elements in XCode seems much easier and much more intuitive to me.

I see there is a ConstraintLayout coming in AndroidStudio 2.2, so maybe that will make things easier in future.

Foundation Libraries

IMHO Out of the box, a basic iOS app is simply nicer looking and easier to use than an Android app. I think the foundation classes on iOS are just better designed. I had to do much more work on Android to make my app half-decent looking, especially with my limited design skills.

XCode

Android Studio is just a little less polished to my eyes. Almost certainly this is because it’s cross-platform, and in a few places you can see this where there are non-standard UI elements used rather than platform specific ones.

It’s not that it’s terrible to use, but XCode just feels faster and looks nicer on OS X.

Summary

I still think developing iOS apps in XCode is easier and frankly more fun than the Android Studio/Android equivalent.

However I was pleasantly surprised how much things have progressed in Android Studio since I first played about with Eclipse a few years ago, and I’ll definitely consider doing more Android work in future.

Android iOS