Finally, things seem not to show up in the correct place, and it turns out because Apple is just being Apple, and forcing people to leave an edge inset on the right of the widget. Fortunately, that was easily fixed:

Autolayout Nightmare

Finally, I have something showing in the widget section. I go ahead and open the main storyboard for the extension, and start adding labels with autolayout constraints and stuff… And that was a complete mess!

After launching the widget, I’d get some error because interface builder is adding runtime constraints just for the heck of it… WHY?!

NSIBPrototypingLayoutConstraint

I didn’t have time to dig into it, so I turned auto layout completely off, and honestly, I didn’t need its power, anyway.

That Freaking Lifecycle

The life-cycle of an extension is, what can I say, whacked. You don’t have a single entry point method that you can use, so your best bet is using a GCD dispatch once in the awakeFromNIB of the main storyboard controller.

What seems to happen is, that iOS destroys your view and recreates it everytime the user hides and shows the notification center. I mean, why? Apple probably doesn’t trust developers with cleaning up properly, so they just dispose the whole view. But then, when it is recreated, you realize that the global state you had is still there, so there is no need to reinitialize it…

In any case, just initialize the global state using GCD, and don’t assume that awakeFromNIB is only gonna be called once, like you would normally assume in a regular app.

Psycho

This is just an arbitrary “wtf” moment I had with extensions…

While programming the extension, I created a new UIView subclass that upon creation, adds some labels as subviews… To my freaking surprise, the labels never get added to the view! It sounds weird, but I did debug it and after addSubview is called, the view would remain empty!

I don’t have time to file a radar or dig deeper, so I wrapped that code in yet another GCD block, that is dispatched asycn on the main thread, that worked, and all is good for now.

Conclusion

I wouldn’t bother making a widget as perfect as possible, in terms of code and features. It’s just not worth the time right now. Just roll out what needs to be rolled out, and move on.