Fix AWSMobileClient to be extension API compatible
Which AWS Services is the feature request for? AWSMobileClient
Is your feature request related to a problem? Please describe. I'm trying to use the AWS SDK using CocoaPods. My application is structured as follows:
- Application
- Core dynamic framework
- Share extension
- Today extension
- Dynamic framework for custom UIViewControllers
- Dynamic framework for third-party service integration
- Dynamic framework for custom business logic
I'm building and linking the CocoaPods dependencies as static frameworks (using the cocoapods-static-swift-framework plugin). What I want to do is merge shared frameworks together into my Core framework and share the Core framework with all of my other frameworks and application. Because Core is used by extensions, it needs to enforce that all code uses extension-compatible APIs. I'm doing this to try to reduce the number of dynamic frameworks that I'm linking against in order to optimize the launch time of my app and extensions, per Apple's guidance.
The problem that I am running into is that AWSMobileClient is not compatible with extensions because of the getViewController function in AWSMobileClientExtensions.swift:
public func getViewController() -> UIViewController {
// This should never get called based on the design
if (developerNavigationController?.visibleViewController != nil) {
return developerNavigationController!.visibleViewController!
}
return UIApplication.shared.keyWindow!.rootViewController!
}
The UIApplication.shared field is not extension compatible since there will not be a UIApplication instance in the extension.
The problem is that I can include all of the other AWS frameworks into my Core framework, but I can't add AWSMobileClient to my main application or another framework because it will fail to find and include header files for AWSCore and AWSAuthCore at build time, based on how CocoaPods builds its frameworks.
Describe the solution you'd like
I would like to see if there's a way to remove the dependency on UIApplication.shared in AWSMobileClient and make the AWSMobileClient extension-compatible by setting the Allow app extension API only flag in order to allow combining AWSMobileClient into a shared dynamic framework along with the other AWS frameworks. There does not appear to be any other blocker except for this one function.
The comment // This should never get called based on the design could be interpreted that this code is not expected to be executed, so can it be removed? Or can it be changed to allow the AWSMobileClient creator to pass a view controller to the initializer? Or add a delegate to AWSMobileClient and have the AWSMobileClient.getViewController call that delegate?
I'm happy to make the change and submit a PR if there's general support for a particular solution.
This would be great to have for us too!
Anyone ?
Will this move forward, anyone?
An example of a similar issue to this being fixed in another library: https://github.com/slackhq/PanModal/pull/81
Adding context from @james-ff in https://github.com/aws-amplify/aws-sdk-ios/issues/2958#issuecomment-677476538
Yes, here I've included additional context for the use case I'm working with: having to use lower level libraries in the meantime to workaround the issue. Ideally only one library (AWSMobileClient) would be shared / linked between the app and extension targets
The AWS SDK for iOS currently only supports iOS applications. Adding support for app extensions will require significant changes to the code. We have this in our backlog but we do not have an ETA or any additional information. We will update this issue as soon as we have more updates.
any update or workaround to get authentication tokens in app extension?
The AWS SDK for iOS doesn't support app extensions. We recommend using Amplify Swift for this -- for more information, please visit https://docs.amplify.aws/swift/
Thanks!