Today Extension Crashes before launching on iOS 8.1.2
Asked Answered
C

4

16

I've been making a today extension that downloads articles from a feed and display the latest ones. The whole thing worked fine on iOS 8, still worked on iOS 8.1, then came iOS 8.1.2 and we started having complaints about the today extension not working anymore. I tried debugging on iOS 8.1.2 devices, and before the extension even launch, it crashes with this error :

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: <__NSConcreteUUID 0x174027280> 5AFB07AB-5DCD-46FE-8D07-44DE0F3789F2)'

I have read this post about frequent bugs happening when developing a today extension : http://www.atomicbird.com/blog/ios-app-extension-tip

In his post, Tom Harrington says :

In iOS 8 (and other recent versions), enabling modules in Xcode's build settings means you don't need to explicitly list all the frameworks you want to use. They'll be found automatically.

But this isn't the case with NotificationCenter.framework, which Today extensions use. If you remove that from the build settings, you won't get any build warnings or errors. But when you try to load the extension, you'll get an exception from libextension.dylib and your extension won't load. The exception message is not enlightening:

2014-08-16 12:06:53.793 TodayTestExtension[41313:6111763] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* setObjectForKey: object cannot be nil (key: <__NSConcreteUUID 0x7fd729422390> ED3B42F8-66CD-4CB0-BCD5-F3DBA6F34DB5)' If you're doing a today extension, just leave that framework in the build settings. It shouldn't need to be there, but it does.

My extension does include NotificationCenter.framework in its build settings, but I suspect my problem might be similar in some way.

Anyone faced a similar problem? Any idea how to solve it?

Codd answered 26/1, 2015 at 15:31 Comment(2)
Wow, that's discouraging. It looks like exactly the same thing, but that's the only thing I know that would cause this problem.Pegram
Were these complaints from users "in the field", or from people running test builds of your app? In the first place it would be an 8.1.2 bug and there wouldn't be much you could do. In the second, it could be an Xcode problem that might be fixable.Pegram
C
1

Eventually I tried to remove NotificationCenter.framework from my target and put it back, cleaned the project, and it's now working again. I guess the framework wasn't properly linked after all, though I could see it on my target with xcode. Also, I can't figure out why it did work, then stopped working with the arrival of 8.1.2.

Codd answered 12/2, 2015 at 13:21 Comment(0)
C
48

This error also occurs if you use NSExtensionPrincipalClass inside "Info.plist" in order to define a base class (instead of using a storyboard) with the name of a ViewController which does not exist.

When using Swift, make sure to prefix the class with the module name (usually the name of the target) like "Module.MyViewController".

Coed answered 23/3, 2015 at 10:34 Comment(4)
Awesome, that worked! I then changed it to $(PRODUCT_NAME)., for an extra bit of flexibility.Imputation
You are saving my life!Unknot
This solution applies to any extension type. And the "When using Swift" part is important. Don't forget that module name.Elwina
Because I change my project name but the info.plist param NSExtensionPrincipalClass also is old project name.Sow
C
1

Eventually I tried to remove NotificationCenter.framework from my target and put it back, cleaned the project, and it's now working again. I guess the framework wasn't properly linked after all, though I could see it on my target with xcode. Also, I can't figure out why it did work, then stopped working with the arrival of 8.1.2.

Codd answered 12/2, 2015 at 13:21 Comment(0)
P
1

I fixed this issue by adding the @objc attribute to the Swift class.

@objc(NotificationViewController)
class NotificationViewController: UIViewController, UNNotificationContentExtension {
...
}
Picrate answered 5/2, 2019 at 8:38 Comment(0)
D
0

Just experienced the same issue. For me, it was "Main Interface" property in "General settings" of the Keyboard target. It was blank, and i set it to my storyboard file and now it works like a charm.Screenshot

Dealt answered 10/2, 2015 at 19:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.