Unable to access files in custom cocoapods iOS Swift - ios

I have implemented custom cocoapods in iOS swift but i am unable to access the file that i have developed in my framework. I have installed the framework using pod install and given the local path to that directory and it is even imported successfully. But when I try to access it, it doesn't finds the file. I have attached the images of the code files below. Please help me out, I will be grateful.
My podspec file is as follows:
Pod::Spec.new do |spec|
spec.name = "MuneebTestCocoapod"
spec.version = "1.0.0"
spec.summary = "A short description of MuneebTestCocoapod.podspec."
spec.description = "The description comes here"
spec.homepage = "http://gitlab.phonecheck.com/muneeb.rehman/muneebtestcocoapod"
spec.license = "MIT"
spec.author = { "Muneeb ur Rehman" => "muneeb.ur.rehman#upgenicsint.work" }
spec.platform = :ios, "11.0"
spec.source = { :git => "http://gitlab.phonecheck.com/muneeb.rehman/muneebtestcocoapod.git", :tag => "#{spec.version}" }
spec.source_files = "MuneebTestCocoapod/**/*.{h,m,swift}"
end

As you check MyService class is a by default internal access level. While you making pod and wants to use outside the module you should need to make your class public or open.
Also, You can't make an instance of MyService class as you added private access specifier to init.
So make it public init and public class.

Related

Create CocoaPod framework with Kotlin shared.framework

I've created a SDK framework and added all files (Swift, Objective C and c++). Also added shared.framework which is written in Kotlin(KMM).
I linked SDK framework into dummy project and working correctly.
Now I've to deliver SDK framework to cocoapod. So for that I've created PodSpec file inside SDK framework and installed it to demo project. It installed successfully, but can't access header files (Objective C) in swift file.
Here is my PodSpec file.
Pod::Spec.new do |spec|
spec.name = "DemoSDKSwift"
spec.version = "0.0.1"
spec.summary = "A short description of DemoSDKSwift."
spec.description = "A very long description of DemoSDKSwift."
spec.homepage = "https://BITBUCKET_URL.COM/DemoSDKSwift"
spec.source = { :git => "https://BITBUCKET_URL.COM/DemoSDKSwift.git", :tag => "#{spec.version}" }
spec.license = "MIT"
spec.author = { "Author Name" => "AuthorName#streamplate.com" }
spec.source_files = "DemoSDKSwift/**/*"
spec.platform = :ios, "15.0"
spec.ios.deployment_target = '15.0'
spec.vendored_frameworks = 'Frameworks/shared.framework'
spec.libraries = 'c++', 'sqlite3', 'z', 'stdc++'
spec.pod_target_xcconfig = {
'KOTLIN_PROJECT_PATH' => ':shared',
'PRODUCT_MODULE_NAME' => 'shared',
}
end
I also have added Bridging header file but it's not working.
I tried so many solutions, but couldn't figure out. Please help to make it working.

How to distribute compiled framework using Cocoapods?

I'm building a framework using cocoapods. Now, I have it in a private repository with a private spec repo. I want to distribute this framework not as open source, but closed source. Basically, I want to distribute only the .framework file, already compiled. This way, I will avoid to expose my source code to externals.
I don't know how to tell cocoapods to distribute the compiled file.
After compiling your framework, you'll want to create a separate, public repository to use for distribution. That is where you will place your compiled framework, podspec, license, readme files, etc.
The podspec is a bit different for distributing frameworks rather than source code. See example:
Pod::Spec.new do |s|
s.name = 'YourFrameworkName'
s.version = '1.7.0'
s.summary = 'The YourFrameworkName iOS SDK enables you to embed state-of-the-art real-time goodness into your iOS app.'
s.homepage = 'http://example.com'
s.author = { 'Name' => 'info#example.com' }
s.license = { :type => 'Custom', :file => 'LICENSE' }
s.platform = :ios
s.source = { :http => 'https://github.com/example/YourFrameworkName/releases/download/1.7.0/YourFrameworkName.zip' }
s.ios.deployment_target = '9.0'
s.ios.vendored_frameworks = 'YourFrameworkName.framework'
s.dependency 'SwiftyJSON', '3.1.4'
end
Once all that is set up, you can publish the pod spec the normal way.
Keep in mind, and this is an important consideration, that your compiled framework written in Swift will only be usable in projects that use the exact same Swift version. You will quickly run into this limitation as people start using your framework in different projects with various Swift versions.
First, you create a sample project and install the pods(the library which you want to release as SDK.framework) for the project.
Then see the below-attached image to get the .framework extension file to distribute to the public.
You can do this by pointing s.source of the podspec file to a zip file of your framework and its source. No need to expose your source in a public repository.
ex.
spec.source = { :http => 'https://bitbucket.org/publicRepo/yourframework.zip' }

Trying to wrap vendor framework in cocoapod but the compiler can't find headers

Hoping somebody has already solved this; I'm trying to wrap a third-party library (Airwatch) in a cocoapod for better management across our apps. I'm having a hell of a time trying to get this to work, though. I've created a pod around a static library, but this one is a dynamic framework, and I'm having a hell of a time getting it to compile. The headers from the framework just aren't accessible in the containing app....
Here's what I have tried already:
When I set vendored_libraries in podspec i can't seem to access headers with either quotes or <>. Xcode just complains as 'Not Found'
Next, I tried adding the path of the headers in the framework as source_files like so
s.source_files = 'Pod/Classes/**/*','Pod/Framework/AWSDK.framework/Versions/A/Headers/*.h'
This allows xcode to find the header for an import like:
import "AWSDKCore.h" //Documented as the framework's main header
But this throws an error for the existing imports within the original framework:
I figured this was a bad idea, but I thought I'd try naming my cocoapod the same name as the Framework (which should keep the import path). So, this throws a bunch of errors saying some enums either aren't declared or are declared twice.
If anybody has thoughts, I'd be eternally greatful...
Just for reference here's my podspec:
Pod::Spec.new do |s|
s.name = "AirwatchSDK"
s.version = "0.1.0"
s.summary = "A short description of AirwatchSDK."
s.homepage = "https://github.com/<GITHUB_USERNAME>/AirwatchSDK"
s.license = 'MIT'
s.author = { "xxxxx" => "xxxx" }
s.source = { :git => "https://github.com/<GITHUB_USERNAME>/AirwatchSDK.git", :tag => s.version.to_s }
s.platform = :ios, '8.0'
s.requires_arc = true
#s.module_name = 'AWSDK'
s.source_files = 'Pod/Classes/**/*','Pod/Framework/AWSDK.framework/Versions/A/Headers/*.h'
s.vendored_frameworks = 'Pod/Framework/AWSDK.framework'
s.frameworks = 'CFNetwork','CoreData','CoreFoundation','CoreGraphics','CoreLocation','CoreTelephony','CoreText'
s.libraries = 'stdc++','z','sqlite3','c++'
end
Since I figured out my own answer, I thought I'd post it here for the next guy...
The key, it turns out, was to not have 'source_files' (or to comment it out). I'm not sure if that is a bug or not, but my final podspec had vendored_framework set and source_files not set like so:
#can't have source files if you want to access vendor framework
#s.source_files = 'Pod/Classes/**/*'
# airwatch framework.
s.vendored_frameworks = 'AWSDK.framework'

No visible #interface in Cocoapods

I am trying to modulize my app by splitting it in different sub projects.
Inspired by this idea. So I splited my project to static libraries followed by that tutorial. I created a first library with some costume UIHelpers/Views. It has some dependencies which I defined in PodSpec file followed by AFNetworking example. (one of the dependencies is Choosy). I stored this library in bitBucket. Everything is working fine for that library(I can build it in Xcode). The problem start when I create a Model Library. I specify Git path of UIHelpers in the Model PodFile. Every time I get an error of No visible #interface for a category in Choosy (the error come from CocoaPod NOT in my project, the category is imported in the .mfile). I tried to play with link flags -ObjC,$(inhereted),-force_load included all of them.Objective-C categories in static library I cleaned the derived data.
I read the CocoaPodTroubleShoutes.
Can somebody suggest what can be tried. There is a lot of question in stuck regarding that compile error but none of them helped me.
I believe the problem somewhere in my PodSpec(cant be sure) pod lib linit I receive :- ERROR | [iOS] Choosy/Choosy/Model/ChoosyAppInfo.m:32:19: error: no visible #interface for 'UIImage' declares the selector 'applyMaskImage:completion:'
My PodSec:
Pod::Spec.new do |s|
#I tried this options:
#s.xcconfig = { 'OTHER_LDFLAGS' => $(inherited) }
#s.compiler_flags = '-ObjC'
#'-all_load'
#$(inherited)
#'-DOS_OBJECT_USE_OBJC=0', '-Wno-format'
#'-force_load'
s.prefix_header_contents = '#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>','#import <CoreGraphics/CoreGraphics.h>','#import "ARNStyles.h"'
s.description = <<-DESC
A longer description of ARNUIHelpers in Markdown format.
DESC
s.homepage = "http://EXAMPLE/ARNUIHelpers"
s.platform = :ios, "7.0"
s.ios.deployment_target = "7.0"
s.source_files = 'UIHelpers/**/*.{h,m}'
s.requires_arc = true
s.subspec 'Choosy' do |ss|
ss.requires_arc = true
ss.compiler_flags = '-force_load'
ss.platform = :ios, "7.0"
ss.dependency 'Choosy'
# ss.xcconfig = { "FRAMEWORK_SEARCH_PATHS" => "$(PODS_ROOT)/Headers/Public/Choosy"}
# ss.ios.public_header_files = 'UIImage+ImageEffects.h'
end
s.subspec 'Dependencies' do |ss|
#ss.ios.public_header_files = 'UIImage+ImageEffects.h'
ss.requires_arc = true
ss.dependency 'FormatterKit'
end
end
In the end it was my fault. The previous developer copied those files from Choosy pod and included it manually.We still use Choosy in other places. Unfortunately the error wasn't clear enough to deduce what was wrong.

Cocoapods with custom framework

I want to generate an podspec-file which has an custom framework, one class and a third party framework as dependency.
The single class refers to the custom framework by including one header of that framework. If I run
pod lib lint
this error appears :
- ERROR | [xcodebuild] /Users/xyz/Documents/iOS/Apps/Sample/Core/Sample.h:10:9: fatal error: 'CustomFramework/Bar.h' file not found
The related part of my podspec file looks like this:
s.source_files = 'Core/*' , 'Core/CustomFramework.framework/Headers/*.h'
s.preserve_paths = 'Core/CustomFramework.framework/**/*'
s.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '"${PODS_ROOT}/Headers"' }
s.frameworks = 'CustomFramework'
s.xcconfig = { 'OTHER_LDFLAGS' => '-ObjC' , 'LIBRARY_SEARCH_PATHS' => '"${PODS_ROOT}/CustomFramework/Headers"'}
s.dependency 'MapBox', '1.1.0'
The single class inherits from class of the MapBox framework.
I feel like I miss something but can not figure out what. Any suggestions or hints?
Try using vendored_framework like explained here: Podspec Link Binary Library
spec.ios.vendored_frameworks = 'Frameworks/MyFramework.framework'

Resources