Skip to content

Since UIApplication.shared is not available in app extensions, anno…#3355

Merged
badboy merged 1 commit intomozilla:mainfrom
ih-codes:66.2.0-fix-application-extension
Dec 16, 2025
Merged

Since UIApplication.shared is not available in app extensions, anno…#3355
badboy merged 1 commit intomozilla:mainfrom
ih-codes:66.2.0-fix-application-extension

Conversation

@ih-codes
Copy link
Copy Markdown
Contributor

@ih-codes ih-codes commented Dec 10, 2025

Followup to #3347.

Unfortunately, we realized after trying to pull in the latest 66.2.0 Glean SDK release that UIApplication.shared can't be exposed in the init API for app extensions. I haven't worked a lot with Swift packages so I apologize not catching this sooner!

Screenshot 2025-12-10 at 11 10 42 AM

The fix is to hide it, or annotate the PingUploadScheduler class as unavailable for iOS app extensions. I opted to hide it so we didn't need to add any restrictions to the package. That said, Firefox for iOS never uses the Glean SDK directly from our app extensions (which are separate processes from the Firefox for iOS client). Instead, we use other ways to pass telemetry back to our main Client.

I was able to set up the Glean SDK framework for local testing with my Firefox for iOS client and this change appears to fix the problem. I will be able to better test future work better this way! 🙏

@ih-codes ih-codes requested a review from a team as a code owner December 10, 2025 17:14
@ih-codes ih-codes requested review from badboy and removed request for a team December 10, 2025 17:14
@badboy
Copy link
Copy Markdown
Member

badboy commented Dec 11, 2025

I was able to set up the Glean SDK framework for local testing with my Firefox for iOS client and this change appears to fix the problem. I will be able to better test future work better this way! 🙏

It's indeed a bit harder than I'd like, if you need help or want us to test out changes before release just let us know and we'll do it.

Copy link
Copy Markdown
Member

@badboy badboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine, but I don't understand the commit message.
Does this work for app extensions, because UIApplication.share only fails at runtime in app extensions, so as long as something else is passed in for BackgroundTaskScheduler it is never instantiated?

Why do that for GleanUploadTaskProvider too, our own type?

(Basically I don't fully understand how this would be used in the app extension part, maybe you can link me how that will be used in ffx iOS?)

@ih-codes
Copy link
Copy Markdown
Contributor Author

(Edit: Hit enter too soon, fixing...)

Does this work for app extensions, because UIApplication.share only fails at runtime in app extensions, so as long as something else is passed in for BackgroundTaskScheduler it is never instantiated?

Actually, it was the Xcode compiler check failing. I was never able to build the app because UIApplication.shared was exposed in the init method (due to it being a default parameter).

What I didn't realize before is that SPMs are compiled for all available targets, regardless if they're actually linked or not. So even though Firefox for iOS is not using Glean for app extensions, the Xcode compiler is trying to compile it that way and failing...

Side note, the use of UIApplication.shared is not permitted in app extensions because they run with a restricted environment and cannot access it. But we don't need to do that anyway.

After thinking about this some more, I think this might be the better fix:
Screenshot 2025-12-09 at 3 29 29 PM

What this does is essentially mark the type as unavailable to use in app extensions altogether.

This was my original solution actually, but after some discussion with my team we decided not to add the limit if we didn't have to. But this is probably safer after all since I can't say what happens at runtime if you were to use the Glean SDK in an iOS app extension which tried to access UIApplication.shared in its implementation.

Why do that for GleanUploadTaskProvider too, our own type?

GleanUploadTaskProvider does not require (in its API or its implementation) the use of UIApplication.shared, so the compiler was not complaining for us there.

(Basically I don't fully understand how this would be used in the app extension part, maybe you can link me how that will be used in ffx iOS?)

The more I think about it, the more I'm thinking we just make the PingUploadScheduler's init unavailable to app extensions. It doesn't seem to make any sense to me if it needs to access UIApplication.shared to schedule background tasks.

@ih-codes ih-codes force-pushed the 66.2.0-fix-application-extension branch from b1a1d37 to 9bb7af0 Compare December 15, 2025 17:36
…ons, as app extensions run in a restricted environment without access to `UIApplication.shared`.
@ih-codes ih-codes force-pushed the 66.2.0-fix-application-extension branch from 9bb7af0 to a0ac8ac Compare December 15, 2025 17:38
@ih-codes ih-codes requested a review from badboy December 15, 2025 17:38
@badboy badboy merged commit 4807504 into mozilla:main Dec 16, 2025
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants