Sunbeam has been in the App Store for just over a month now, and today I’m proud to release its first major update – Sunbeam v1.1.
- Today widget: Sunbeam now comes with a Today widget. Just swipe right on your home screen or 3D Touch on the Sunbeam icon to get the current UV index at a glance.
- Visual improvements: Visual updates to improve the look and feel of the app.
- Better perfromance: Improvements to the server mean that the app can now fetch your weather data significantly faster than before.
- Better hourly forecasts: Sunbeam now only shows you UV forecasts for daylight hours, making it quicker and easier to find the forecast data you want.
- Solar Noon: Easily see what time the sun will be at its strongest.
The main change to Sunbeam’s code base is the addition of a Today widget, which shows your latest UV forecast at a glance when you swipe right on your home screen (or 3D Touch the app icon on some iPhones). In iOS, widgets operate as separate processes to the main app they’re bundled with, so you effectively have to code them as distinct applications.1 That could of course lead to lots of duplicate code were you to try and replicate core bits of the main app’s functionality in a widget. To avoid breaching the software engineering principle of DRY (don’t repeat yourself) and ending up with an unwieldy code base, I found that the best way round this problem was to encapsulate shared functionality – such as networking and geolocation code – in a custom framework. This enables the same code to be shared between both the app and the widget (and actually, if you have multiple applications, this approach even lets you share code between them).
Fortunately in Sunbeam’s case, the process of separating out shared functionality into a new framework (which I’ve called UVKit) was relatively trivial. As I’ve followed the standard iOS MVC design pattern, for me essentially all this meant was moving my model code into the new framework and then hooking it back into the main app. This did involve some extra steps to make sure the main app and the extension play nicely together (for example, setting up group keychain access and allowing the Today widget to access the same CloudKit container as the main app), but the whole process was relatively painless. If you’re looking to implement a Today extension for your own app, I recommend this useful tutorial from Ray Wenderlich as a good place to start.
One quick and easy (but, from a downloads perspective, potentially significant) behind-the-scenes change to the app is that it will now prompt users for an App Store rating once certain conditions have been met. Apple couldn’t have made this easier to implement with the SKStoreReviewController’s requestReview() method, but there are a couple of important considerations to keep in mind here:
- As a developer you can ask iOS to request a review; however there is no guarantee that your request will be fulfilled, and Apple will only allow the review prompt to be displayed to any given user a maximum of three times in a 365-day period.
- You don’t want to annoy your users with poorly timed review prompts, so it’s worth giving some consideration to exactly when you want to call the requestReview() method.
I’ve settled on what I hope is a reasonable approach in Sunbeam, which is that users will only be asked to provide a review when all three of the following conditions are met:
- The user has not previously been asked to review the currently installed version of the app.
- The user has launched the current version of the app a minimum of 10 times.
- The app has just successfully obtained a UV forecast for the user’s current location.
I’m hoping that this approach will get me reviews from regular users of the app who are satisfied with their experiences, while avoiding bombarding people who are new to the app or who have only recently been prompted for a review.
That’s about it for the current release, so I hope you enjoy the new features. I’ve already got some ideas for the next version of the app, so follow me on Twitter @the_richardj for updates.
- Today widgets aren’t actually apps – they’re just view controllers that are presented inside a host app (in this case Springboard). ↩