Is there a way to add Flutter to an extension Target on iOS xCode? - ios

Assuming I have a basic flutter app and I add a target in xcode for the ios app. Would there be any way to link it to the main Flutter folder so I can do an "import Flutter" in the extension the same way it's done in the AppDelegate then start a FlutterEngine, MethodChannel etc locally in the extension ?
I partially succeded adding a module compiled as an "ios-framework" (otherwise with cocoapods there's a dependency conflict error) to the extension xcode target, yet this means including a redundant Flutter dependency and although it runs, I'm not sure at this point this is very stable... For this reason I'm wondering if there's a way to make an import of the main Flutter directly ?
Thanks

Related

No such module 'Firebase' - Xcode and Swift Package Manager

I'm trying to incorporate Firebase Analytics into my SwiftUI project in Xcode. I've added the Firebase package using Swift Package Manager, and am able to call FirebaseApp.configure() to initialize my app in my UIApplicationDelegate class. Now I'm trying to log analytics events and am running into an issue.
My UIApplicationDelegate class is in an iOS-specific folder. I have a service class that is in a Shared folder (to be used across both iOS and macOS builds). In my service class, I've added a line that says:
import Firebase
However, when I go to build my iOS target I get an error saying:
No such module 'Firebase'
I don't know why this import statement would cause a problem, since I have the very same statement in my UIApplicationDelegate class. The only thing I could think of was that somehow my Shared classes don't know about Firebase? Maybe? When I view the iOS target in my project it shows that the FirebaseCrashlytics and FirebaseAnalytics frameworks have been added to it.
I'm at a loss as to what's happening. All other things I've found online are for Cocoapods, which I'm not using for dependency management. I'm leveraging the Swift Package Manager for this. Any help would be greatly appreciated!!
I had the same issue but the post below from GitHub should fix it:
https://github.com/firebase/firebase-ios-sdk/issues/9014#issuecomment-979489434
After installing the Firebase swift package, make sure you add the Firebase libraries to Frameworks:
TARGETS -> Your App -> General -> Frameworks, Libraries, and Embedded Content -> hit '+' to add the Firebase libraries you want:
I had the same error but with 'FirebaseCore'. I tried everything, but what worked for me was to add #_implementationOnly to import. So it should look like this:
#_implementationOnly import FirebaseCore
Here is the link that helped me and it says:
You could use #_implementationOnly import for the modules from the
third-party SDK if you aren't using anything from that SDK as part of
your module's public interface.

How can I properly share the Amplify framework with my Main App and my App Extension for an iOS app?

I have an iOS app using AWS amplify for the backend. I am using Xcode 13 and SwiftUI.
I previously added the Amplify framework using Cocoapods however I was unable to get the framework to work with the extension.
So I recently switched to Swift Package Manager. I added the package to my main project. Then I went to my Share Extension and in General - Frameworks and Libraries and manually added the libraries.
After doing this the app builds and runs and both the main app and extension work fine and are able to use the libraries.
The problem is that I cannot archive and upload the app to the App Store. I get the following error:
CFBundleIdentifier Collision. There is more than one bundle with the
CFBundleIdentifier value 'com.amazonaws.AWSAuthCore' under the iOS
application 'MyAPP.app'. With error code
STATE_ERROR.VALIDATION_ERROR...
I went on many forums and spent many hours trying to fix this but to no avail. The suggestions are to click 'do not embed' for the libraries but that option is not available for me.
I wonder if there is anyway to resolve this?
Below are my General and Build Phases for the Share Extension:
Just remove explicit Amplify dependency from extension, ie. next section should be empty
Make sure (it should be automatically, but anyway)
Link Frameworks Automatically parameter (in Build Settings) is true
Runpath Search Path parameter is related to main bundle
So as targets from SPM are built in same location as product and extension and automatic framework linking is enabled the imported modules in extension will available and linked automatically and due to run paths are set the frameworks will be found in run-time as well.
Note: of course in main app target all should be included
Tested with Xcode 13.1 / iOS 15.1

"UserNotificationsUI" is not available when building for UIKit for Mac error

My app has Service & Content Extension Notifications targets for
supporting Rich Remote Notifications which work as expected on
iPad/iPhone iOS 13 & below
I have installed Xcode 11-beta & macOS Catalina 10.15-beta
On building with the new UIKitForMac I get the following error -
"UserNotificationsUI" is not available when building for UIKit for
Mac. You may need to restrict the platforms for which this framework
should be linked in the target editor.
First tried adding #if canImport() ... #endif around instances of UserNotificationsUI which didn't work
Then removed the Extension Targets which is also not working.
Anyone facing a similar issue?
A closed source Third party framework that I was using had UserNotificationsUI linked.
The build error was because UIKitForMac doesn't support Mobile specific frameworks like UserNotifications which is the correct behaviour.
Removing the Third Party dependency resolved the issue for me.

Integrate Flutter into CocoaTouch SDK?

I was able to follow the instructions on https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps to add Flutter as a dependency to a simple single view app and display a FlutterViewController, but did not have success trying the same process for a cocoa touch framework that depends on Flutter.
Is this currently possible? My hope was to be able to build a standalone iOS SDK that is powered by Flutter that other iOS apps could depend on with no direct dependency on Flutter.
Specifically when I tried the SDK approach, Flutter imports failed to resolve with errors relating to not being able to find the Flutter module imports:
[Xcode build error][1]][1]
error: no such module 'FlutterPluginRegistrant'
import FlutterPluginRegistrant
error: no such module 'Flutter'
import Flutter
Update:
These are the error logs I was seeing initially, but was able to get around them by vendoring the FlutterPluginRegistrant.framework and Flutter.framework with Cocoapods. With that my main app compiles fine when linked to my FlutterSDK framework that includes the flutter dependencies. The issue I'm running into now is with setting up FlutterViewController and it's FlutterEngine / FlutterDartProject to point to the correct paths within the framework for the flutterAssets / dartMain / packages urls. I'm not sure how to pull these in from the framework.
If you want to build a Framework that is essentially _just_ a Flutter module, where other iOS apps can use it without having to install/depend on Flutter SDK themselves, then yes, this can be done via one of the flutter/add-to-app options for iOS:
Option B - Embed frameworks in Xcode
also refer to the github/flutter/ios_using_prebuilt_module sample
On the other hand, if you are talking about integrating Flutter into an existing Framework, Flutter + Cocoa Touch, then no, this is currently not supported, but is being explored:
https://github.com/flutter/flutter/issues/39027
note that this would be termed “add-to-library” as opposed to "add-to-app"
also mentioned, flutter/add-to-app:
Packing a Flutter library into another sharable library or packing multiple Flutter libraries into an application isn’t supported.

Cocoa Touch framework shared between iOS and tvOS

I'm working on an app that can have some shared code that I want to encapsulate in a framework. I created iOS Putter app target, then a framework PutterKit that I link from the app. This works fine.
Then I create a tvOS app target PutterTV and duplicate the PutterKit to PutterKit (TV) and set its sdk to tvOS
When I import PutterKit in the tvOS app and compile it, I get the error
No such module 'PutterKit'
Here is a sample project
https://dl.dropboxusercontent.com/u/1326174/Putter.zip
What is the correct way to setup such a framework?
Looking at your project, you need to:
import PutterTVKit
If you look at your PutterKit(TV) target build settings, you will notice that the ProductName and ProductModuleName are PutterTVKit.
Also make sure that in the Linked Frameworks and Libraries section in PutterTV app target, you link in PutterTVKit.framework (not PutterKit.framework).
With these changes, it appears to compile fine.

Resources