WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

SOLVED - Ultimate Portfolio - sharedApplication unavailable to app extensions?

Forums > Articles

When making extensions for DataController to be used by a widget as mentioned in "Creating a simple widget", I get the error "'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead."

This error occurs in appLaunched() in the DataController.swift file, and in the video I can see that Paul has commented out at least the one offending line in the appLaunched() code. Unfortuanately vidoes don't scroll ;-)

Has anybody else experienced this error, and what was your workaround it?

1      

Not sure what the work around is yet, maybe that is a question for the next video, or a later Q&A session.

The lines are to do with inApp purchases and StoreKit, and the issue when adding a Quick Action to the app icon. See this video Add Quick Action to the icon at around 9:00 minutes.

2      

Hmm, for now it seems I have to choose between offering a review or a widget. Yep, waiting for the next episode seems like a good idea.

By the way the Apple Documentation explains what an app extension can do or not do: https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/index.html

And I've seen some suggest some build options settings that will supress the error, but that is hardly a solution…

1      

Well, the next video Creating a second widget did address this point, right at the end of the video.

With the explanation it is obvious what the workaround should be. I think that the workaround technique is a generally useful one, and can be applied to a great many situations.

1      

I wrote this question before that article came out, and it solves my question. Thanks for the input @Greenamberred 😀

1      

@loseth You're welcome. The Creating a second widget video only came out yesterday / last night.

1      

Hacking with Swift is sponsored by Emerge

SPONSORED Optimize your app’s startup time, binary size, and overall performance using Emerge’s advanced app optimization and monitoring tools. Reliably measure app size, speed up your app's startup time with Emerge's Launch Booster, and much more. Emerge is actively used by many of the top mobile development teams in the world.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.