Category Archives: apple

Swift, Obj-C, AppleScript and AppStore fun.

Apple: You recompiled. Let’s make that crash now.

tl;dr – UIApplication.shared.idleTimerDisabled now causes an undocumented crash if you compile with the iOS 13 SDK and use it from a background thread.

Photo by Zach Savinar on Unsplash

VLC Streamer is one of my oldest apps. It has been going strong since 2008!

It’s a pretty complex app with a bunch of different code paths and edge cases. It’s mostly written in Objective-C.

I uploaded a new build on Jun 15, 2019 to deal with some details around new device screens. No problems there.

I uploaded again on November 20th. There were two relevant changes.

  1. I updated the base SDK to 11.0 (from 9.0)
  2. I compiled with the latest XCode using the 13.0 SDK

I woke up on the 22nd to get loads of crash reports. One of my code paths calls this from a background thread:

[[UIApplication sharedApplication] setIdleTimerDisabled:YES]; 

This now causes a crash.

Three things of note here for me

  1. Nothing in the documentation says you can’t call idleTimerDisabled from a background thread.
  2. No code has changed. I just recompiled and resubmitted. The old build worked, the new build crashes.
  3. Why is this even an issue? If Apple really need this flag to be changed on the main thread – couldn’t they dispatch it to main in the implementation?

Of course – better testing would have caught this, but how many of us really have proper UI testing in all of our code paths…

Update:

Building a test app with iOS 9 as the target still gives the crash.

Presumably this means that the change has come from using XCode 11.2.1 and the iOS 13 SDK.

Overreaction vs Sanity. Google Play vs Apple Store.

In the last week or so, both Apple and Google informed me that one of my apps was in a small way breaching store guidelines.

Photo by Jorge Fernandez on Unsplash

I’ll paraphrase both messages here:

One of your apps hasn’t been updated in years. It doesn’t meet current guidelines. If you don’t update it – we’ll remove it in 30 days.

Apple

and

One of your apps breaks the metadata guidelines. It has a quote in the app description.

We have removed it from the store.

Google

Both complaints are probably valid. The iOS app hasn’t been updated since 2015 and hasn’t been optimised for the latest devices. I’ll update it this month.

The Android app did have the following quote in the store description

VLC Remote is the latest Android app to earn my favor, and it’s a beauty

Androidnica

The quote has been there for at least 5 years. I’m not entirely sure whether it should count as a ‘user testimonial’ (banned) or a ‘third party review’ (I think those are ok). But either way – I’m happy to remove it.

Removing my app from the store just seems like a Massive Overreaction when they could simply have emailed me to request a change.

What does a red dot mean Apple?

Every now and again – Apple demands my attention with a red dot on the System Preferences in the dock

When they do – I launch the preferences app, and my eye is immediately drawn to the icon at the top right on the ‘Notifications’ icon

Of course – that red dot isn’t a notification dot. That’s an icon of a notification dot – not an actual notification dot

I’m supposed to ignore that one, and look for the second one on the ‘software update’ icon

That’s just bad UI

Update – Catalina

Apple have fixed this as of Mac OS 10.15

Easier iTunes Connect Sandbox Users with GSuite Routing

Use GSuite Routing to dynamically handle different iTunes Connect test emails.

iTunes connect testing is a pain. One of the pain points is that you have to create a bunch of iTunes Connect accounts when you want to test your purchase flows. Each of those needs a separate email address.

You used to be able to do this with the magic

  • rob+test1@hobbyistsoftware.com
  • rob+test2@hobbyistsoftware.com

And all your emails would be routed through to rob@hobbyistsoftware.com (this works for gmail, and many other email providers)

Sadly Apple disabled this capability some time in 2018 (?) – so now you need a new valid email address for every iTunes Connect sandbox user

GSuite Routing provides a neat way to restore this functionality

  1. Open your GSuite Management Console
  2. Click through to Apps > G Suite > Gmail
  3. Click on ‘Default Routing’
  4. Click ‘Add Setting’ and add something like the following

(note – the regexp is rob_.*@hobbyistsoftware.com)

This redirects all email of the format rob_something@hobbyistsoftware.com to rob@hobbyistsoftware.com

Your icon can’t look like an iMac

After about 10 updates with my new icon for Multi Monitor Wallpaper, Apple decided to reject an update because

Guideline 5.2.5 – Legal

Your app does not comply with the Guidelines for Using Apple’s Trademarks and Copyrights. Specifically, your app includes:

– Apple trademark, iMac profile/ image, imagery – or likeness – in the icon

This icon is not OK any more:

This icon is fine (for now)

Notice the narrower bezel and narrower darker stand. Apparently that makes all the difference 🙂

To be clear – the icon clearly was inspired by the iMac, though it is custom built by a third party, and not based on Apple artwork.

Anyway Multi Monitor Wallpaper has a new icon.

ITunes: You’re doing it wrong. I could help – but I won’t.

I just tried to redeem a code for a Mac app through iTunes.

Apple identify that I’m using the code in the wrong place and tell me what to do (use the Mac App Store), but they could easily do better.

Better: Instead of a red error message – why not give me a link that opens the Mac App Store with the code pre-filled?

According to Stack Overflow, this link used to work:
macappstores://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/redeemLandingPage?code=NHWEL3FHRYKR

As of April 23rd 2019, that link opens the right page – but doesn’t pre-fill the code. (I have filed a bug)

Best: Why not just redeem the code for me? I’m already logged in on my mac with the right account.

Apple auto-updates Xcode, but you can’t submit with it

I woke up this morning to find that my Mac auto-updating from Xcode 10.1 to Xcode 10.2

Amongst other things, this disables Swift 3, and introduces Swift 5.

So – after updating a fork of one of the libraries I use, I updated my own code to Swift 5 and submitted to the App Store. Only to find the following:

The newly released version of XCode can’t be used to submit apps.

It turns out this is standard practice from Apple

This isn’t good enough. This kind of thing needs a checklist:

Xcode Release Checklist

  • Has it been tested
  • Can developers use it
  • Really? Can developers submit builds with it?
  • Even Mac Apps?

It’s fine to release beta versions that we can’t use.

It’s not cool if release versions don’t work.

Is It Working will stay free for some time…

I started Is It Working as a ‘side project’.

(Is It Working checks that your SSL certificates are not expiring, and that your background server processes are running as expected)

I admit – I had hopes that it would be a huge instant success with hundreds or even thousands of users – and I’d be instantly rich 🙂

via Giphy

Sadly this didn’t happen. Folks are using IsItWorking – but the numbers are not huge.

On a related note, EU tax law has an annoying ‘feature’ where if you sell a single pound worth of digital services, you need to register for sales tax and send reports every three months.

I’m allergic to that kind of admin.

So, given that I don’t want to do the admin, and that it would be a chunk of work to add a payment system to Is It Working – I’m not going to.

This is not to say that I’ll never charge – but if I do start charging, I’ll give reasonable notice, and I won’t charge current users more than $1 / month for 10 checks.

This also means that I’m not doing significant work on Is It Working.  I’ll keep it running because

  • I think it is cool
  • I use it for my own purposes

Of course – if you have a feature you’d like to see, I’m happy to add features on a sponsored basis.
I hope Is It Working will still be useful for people. If you like it – please tell your friends.
Perhaps I’ll still be rich some day 🙂

HSNotifications – Easier Better Notifications in Swift

Introducing HSNotifications. A simple, sensible, easy-to-use wrapper around NSNotificationCenter

Let’s jump straight in. I mostly use notifications to keep my UI up to date. That means ViewControllers end up with a bunch of observers that need to be activated and de-activated with the ViewController lifecycle

Easy ViewController Integration

class ViewController: NSViewController, HSHasObservers {
    
    override func viewDidLoad() {
        super.viewDidLoad()

        //Create and add
        HSObserver.init(forName: Foo.didAThing,
                            using: { (notif) in
                                //Do Something
        }).add(to: self)
        
        //Monitor multiple notifications
        HSObserver.init(forNames: [Bar.oneThing,Bar.anotherThing] ,
                            activate:true,
                            using: { (notif) in
                                //Do Something Else
        }).add(to: self)
    }
    
    override func viewWillAppear() {
        super.viewWillAppear()
        
        activateObservers()
    }
    
    override func viewDidDisappear() {
        super.viewDidDisappear()
        
        deactivateObservers()
    }
}

Taking this step by step:

ViewController uses the protocol HSHasObservers

This allows us to add observers to the ViewController (they are stored in the observers array)

Next we create an HSObserver object. The block will be triggered by any Foo.didAThing notification.

We take sensible defaults

  • Assume you want to use NSNotificationCenter.default
  • Assume you want your block to fire on the main queue
  • Assume you don’t care what object broadcasts the notification.

(Of course – you can override any of these if you want to.)

The observer is added to the ViewController with .add(to:self)

Next we add an HSObserver to observe multiple Notifications

Finally, the observers are activated and deactivated in viewWillAppear and viewDidDisappear

When the ViewController is released, they are cleaned up automatically.

Standalone Observers

    var waveObserver:HSObserver
    init() {
        waveObserver = HSObserver.init(forName: Watcher.wave,
                                           using: { (notif) in
            //Do Something
        })
        
        //activate
        waveObserver.activate()
        
        //deactivate
        waveObserver.deactivate()
    }

HSObserver objects can be stored as a standard variable.

This allows them to be activated and deactivated.

They clean up properly when they are released with the owning object.

There are of course lots of options available here.

    /// Create observer
    ///
    /// - parameter name:  notification name
    /// - parameter obj:   object to observe (default nil)
    /// - parameter queue: queue to run the block on (default main)
    /// - parameter center: notification center (default NotificationCenter.default)
    /// - parameter block: block to run (beware of retain cycles!)
    ///
    /// - returns: unactivated manager. Call activate() to start
    convenience init(forName name: NSNotification.Name, 
                     object obj: Any? = nil,
                     queue: OperationQueue? = .main,
                     center newCenter: NotificationCenter = NotificationCenter.default,
                     activate: Bool = false,
                     using block: @escaping (Notification) -> Swift.Void)

Get HSNotification at GitHub