fermoya / cocoapods-catalyst-support

Ruby extensions to help you configure your pods project so that pods not compiled for Catalyst can still be used for iOS devices
MIT License
111 stars 18 forks source link

Issue with Objective-C Bridging header #35

Closed stan96D closed 2 years ago

stan96D commented 2 years ago

Describe the bug When compiling our project we encounter an error which states the content in our Objective-C Bridging header isn't found. Also the macro doesn't work in such file so we aren't able to exclude it. But once we comment out the content of the Bridging header the project works fine on Mac Catalyst, however it doesn't on iOs since the Bridging header data is missing. Is there some other way in achieving this? Hope I'm clear.

Podfile require 'cocoapods-catalyst-support'

platform :ios, '9.0'

target 'AzionBaseApp2' do use_frameworks!

pod 'SwiftKeychainWrapper' pod 'Alamofire', '~> 5.2' pod "SwiftSignatureView", :git => 'https://github.com/jvigneshcs/SwiftSignatureView.git' pod 'IQKeyboardManagerSwift' pod 'EAN13BarcodeGenerator' pod 'StarIO' pod 'StarIO_Extension' pod 'StarIODeviceSetting' pod 'DropDown', '2.3.13'

end

catalyst_configuration do verbose!

ios 'StarIO' ios 'StarIO_Extension' ios 'StarIODeviceSetting' end

post_install do |installer| installer.configure_catalyst end

Environment cocoapods-catalyst-support (0.2.0) ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.x86_64-darwin21] 1.9.3 Xcode 13.2.1 Build version 13C100

fermoya commented 2 years ago

@stan96D let me get this clear. You have a private pod which has an Objective-C Bridging header. The problem you're experiencing is those frameworks referenced from that header are still marked to be compiled for macCatalyst, that is, they're not excluded as dependencies. Is that right?

stan96D commented 2 years ago

@fermoya Sorry if it wasn’t clear but yes, that’s the case.

fermoya commented 2 years ago

@stan96D it was very clear, just wanted to make sure I understood correctly. I'll take a look. I'm not sure why that happens, but do you think you could create a sample project for me to take a look? Otherwise I'll try to reproduce it myself

fermoya commented 2 years ago

@stan96D can you show me what your bridging header looks like? I don't think this file should be excluded as you might want to be adding frameworks or files that are needed for macOS

Your bridging-header should look something like this:

#if __has_include(<SomeModule/SomeModule.h>)
#import <SomeModule/SomeModule.h>
#define __HAS_SOME_MODULE_FRAMEWORK__
#endif

And then, if you had any Objective-C code:

- (void)doSomething {
    #ifdef __HAS_SOME_MODULE_FRAMEWORK__
    // with  SomeModule framework
    #else
    // without  SomeModule framework
    #endif
}

And your Swift code:

#if canImport(SomeModule)
import SomeModule
#endif

Let me know if that helps.

stan96D commented 2 years ago

Allright man thanks a lot! Here's the content of my Bridging header.

import <StarIO/SMPortSwift.h>

import <StarIO_Extension/StarIoExt.h>

import <StarIO_Extension/StarIoExtManager.h>

import <StarIO_Extension/SMBluetoothManagerFactory.h>

import <StarIO_Extension/SMSoundSetting.h>

// To use StarIODeviceSetting.xcframework, you also need to write the following lines.

import <StarIODeviceSetting/StarIODeviceSetting.h>

I'll try the things you suggest and report back if I encounter something useful.

stan96D commented 2 years ago

@fermoya Hi man, I did the things you mentioned and it worked! Thanks! This is the Bridging header I ended up with;

if __has_include(<StarIO/SMPortSwift.h>)

import <StarIO/SMPortSwift.h>

endif

if __has_include(<StarIO_Extension/StarIoExt.h>)

import <StarIO_Extension/StarIoExt.h>

endif

if __has_include(<StarIO_Extension/StarIoExtManager.h>)

import <StarIO_Extension/StarIoExtManager.h>

endif

if __has_include(<StarIO_Extension/SMBluetoothManagerFactory.h>)

import <StarIO_Extension/SMBluetoothManagerFactory.h>

endif

if __has_include(<StarIO_Extension/SMSoundSetting.h>)

import <StarIO_Extension/SMSoundSetting.h>

endif

if __has_include(<StarIODeviceSetting/StarIODeviceSetting.h>)

import <StarIODeviceSetting/StarIODeviceSetting.h>

endif

I also added the if statements to exclude the pods for Mac Catalyst.

It works like a charm, five stars!