What I learned today or: Swift 3 & SpriteKit trials and tribulations
By the latest numbers available at the time of writing this, the iOS 10 adoption rate is 79% (Feb 20, 2017). Leaving 1OS 9 at a mere 16% and all earlier variations at 5%. By those numbers why should we care about iOS 9? I mean how many devices could that possibly be? According to Apple on Jan. 26 2016 they reached their one billionth active device. Keep in mind that is over a year ago and does not include iPhone 7 sales with those numbers. My calculations put that at 160 million active iOS9 users (actively accessed the Apple App Store within the last 60 days). Now in the struggling business of the independent app/ game developer where EVERY download counts the iOS 9 tally might as well be 1 trillion.
Why do I care about iOS 9 numbers today? During a recent conversion from Objective-C to Swift 3 for one of our existing games (Crag & Pig), we were testing local push notifications, and Apple has introduced a new framework for notifications UNUserNotifications which doesn’t play well with iOS 9. No problems we can write some code saying if iOS 10 run the new framework else if iOS 9 run the old UILocalNotification framework. No big deal, kind of a pain in the ass but so be it. While testing the notifications on an iPad mini 1 running iOS 9 (the iPad mini is not eligible for iOS10 upgrade) our game never even loaded, crashed right out of the gate. Must be the notifications, nope.
With Xcode 7 and iOS 9, Apple introduced the ability to save an action, or a group of actions, to a file and then reference this action by name in code, or drag and drop from the actions panel in the editor itself. Saving these actions allowed for future repeated use as a ReferenceNode, and meant that actions could be shared by multiple objects and didn’t have to be recreated for each use, it also meant that if you want to tweak those actions you were able to edit in one place and the changes would propagate to any instance using the reference. Great! In our MenuScene scene file (sks) we had some saved actions for clouds scrolling by in the distance, and we reused those actions in our GameScene file. This is awesome, we get to remove a whole sub-class file for clouds and we get to remove 20+ lines of code twice from two separate files that instantiate these 6 clouds and move them across the screen. This is a perfect example of taking something so minute and moving it to the background and not giving it any attention which they didn’t deserve. But after much commenting out and deleting objects, it turns out that the referenced saved actions are what was causing the game to crash in iOS 9. But why would these saved actions crash a device if they were introduced in iOS 9? It turns out that they were introduced in iOS9 with serious bugs and not fixed until iOS 9.2 (Apple Dev Forums).
Dilemma time, do we just change the “Deployment Target” field in Xcode to 10.0 ignoring 160 million users and move on with life? or do we go back remove all of the saved actions ignore this great feature by Apple? when you are monitoring your daily downloads in the double digits It seems pretty obvious that this yet another one of Apple’s great introductions that won’t get utilized until two iOS versions later. So we went back, and took out all of the saved actions, created a sub-class for Clouds added 20+ lines of code in our MenuScene & 20+ lines of code in our GameScene to start up those clouds, and wiped that smug smile off our face at the thought that we had come upon something great with these saved action files and went back to work.