3

When defining my Podfile as below, and then building my app with my extension I get a build error in the DKImagePickerController framework with an error similar to this: Error "'sharedApplication' is unavailable: not available on iOS (App Extension)...." when compiling after pod update

As you can see I have not included the DKImagePickerController framework in my extension target in my Podfile, so I'm wondering what I am doing wrong?

 platform :ios, '10.0'
    def base_pods
      pod 'Firebase/Core'
      pod 'Firebase/Auth'
      pod 'DKImagePickerController', '~> 3.4.0'
      ...
      pod 'SAMKeychain'
    end

target 'MyApp' do

  use_frameworks!
  base_pods

  target 'MyAppExtension' do
    pod 'Firebase/Auth'
    pod 'SAMKeychain'
  end

  target 'MyAppUnitTests' do
        inherit! :search_paths
        pod 'Firebase'
        pod 'FirebaseAuth'
        pod 'FirebaseUI/Auth'
  end
end

Update

I appreciate that I am getting the error due to an API being unavailable, what I am trying to figure out is how to avoid it. My suspicion is on my podfile, hence my question :)

Community
  • 1
  • 1
Chris
  • 7,830
  • 6
  • 38
  • 72

2 Answers2

4

I had the same issue, so for anyone else finding this thread, I was able to solve the problem by creating two top-level targets instead of using a nested target.

target 'MyApp' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyApp
  pod 'Eureka', '~> 3.0'
  pod 'ChameleonFramework', '~> 2.0'
  pod 'SharedPod', '~>1.0'

  target 'MyAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'MyAppUITests' do
    inherit! :search_paths
    # Pods for testing
  end
end

target 'MyApp Today' do
  use_frameworks!
  # inherit! :none
  # Pods for MyApp Today
  pod 'SharedPod', '~>1.0'
end

To get a clean start I then ran...

pod deintegrate
-- Then cleaned out the project file in XCode
pod install
3Stone
  • 143
  • 6
0

There are few API's which are unavailable in App Extension's. One of them is UIApplication. The framework developer has to make sure this never happens. https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionOverview.html#//apple_ref/doc/uid/TP40014214-CH2-SW6

Sachin Vas
  • 1,757
  • 12
  • 16
  • Sachin, I appreciate that, I should have made it clearer that I know why the error is occuring. Iøm trying to figure out how to avoid this error – Chris Jan 21 '17 at 11:17
  • You need to check with the DKImagePickerController framework developers. They need to duplicate the original scheme and then add the source with the pre-processor macro which will avoid compiling the App extension unavailable API's. This leads to duplication of code, read http://blog.cocoapods.org/CocoaPods-0.38/#target-deduplication – Sachin Vas Jan 22 '17 at 04:14
  • But I dont want to include that framework in my target. That's the whole point. Why is it even complaining about it when it's not specified as a dependancy in my podfile? – Chris Jan 22 '17 at 08:42
  • Then I think you are compiling the class which uses the DKImagePickerController in the App Extension. – Sachin Vas Jan 23 '17 at 02:48