grepLines
grepLines

Reputation: 2558

How to import iOS native framework into Flutter?

I want to contribute in this Flutter_blue plugin project adding the functionalities for native iOS using Objective C framework CoreBluetooth. How do I import the framework in to the library so I can start using its APIs?

Update:

CoreBluetooth is not suitable for Flutter project, because it's not a cocoapod dependency. So what I did what, go to cocopods website and look for other bluetooth dependencies from there. You can also find instructions of how to install a dependency there. For me, I made added pod <depdencyname> to <plugin-project>/example/ios/Podfile in the plugin project. Then added dependency: <dependencyname> to the in <plugin-project>/ios/pubspec

Upvotes: 7

Views: 9390

Answers (2)

Miguel Ruivo
Miguel Ruivo

Reputation: 17756

I had the same problem for a few time and found a solution by adding this lines to your podspec file at your iOS/ folder in your plugin dir:

  s.preserve_paths = 'yourframework.framework'
  s.xcconfig = { 'OTHER_LDFLAGS' => '-framework yourframework' }
  s.vendored_frameworks = 'yourframework.framework'

Then, on your Flutter project, in the iOS folder, just run pod update on terminal so it can fetch the new dependencies.

You can find the full issue open by me with this problem here.

Upvotes: 3

RedBrogdon
RedBrogdon

Reputation: 5351

If you're looking to add a CocoaPod dependency to the iOS "half" of a Flutter plugin, I believe the correct way to do so is to update the podspec file in the /ios folder of the plugin source. I recently did some work on the AdMob plugin, for example, and its podspec lists the SDKs for Firebase and Google Mobile Ads:

https://github.com/flutter/plugins/blob/master/packages/firebase_admob/ios/firebase_admob.podspec

And that's how they get included in the build.

Upvotes: 2

Related Questions