3

I've recently started doing iOS and I'm attempting to integrate the Vitamio Objective-C library with my Swift Project. I use CocoaPods to import various swift libraries. Vitamio is integrated with a bridging-header file.

Bridging-Header File

#ifndef inclub_Bridging_Header_h
#define inclub_Bridging_Header_h

#import <Foundation/Foundation.h>
#import "VDefines.h"
#import "VPlayerManageDef.h"
#import "VMediaPlayer.h"
#import "VMediaPlayerDelegate.h"
#import "VMediaExtracterDef.h"
#import "VMediaExtracter.h"

#endif /* inclub_Bridging_Header_h */

PodFile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target 'inclub' do
    pod "Player", "~> 0.2.0"
    pod 'Alamofire', '~> 4.0'
    pod 'Kingfisher', '~> 3.0'
    pod 'ObjectMapper', '~> 2.2'
    pod 'UIImageViewAlignedSwift'
    post_install do |installer|
        installer.pods_project.targets.each do |target|
            target.build_configurations.each do |config|
                config.build_settings['SWIFT_VERSION'] = '3.0'
            end
        end
    end
end

Sample Swift File

import Alamofire
import Foundation

class BackEnd {
    typealias JsonResponseHandler = (_ response: DataResponse<String>) -> Void
    typealias ErrorHandler = (_ error: Error) -> Void

    let defaultSession = URLSession(configuration: URLSessionConfiguration.default)
    var dataTask: URLSessionDataTask?


    static func tabletLogIn(user: String, password: String, responseHandler: @escaping JsonResponseHandler,  errorHandler: @escaping ErrorHandler) {
        let url = UrlFactory.getLogInUrl(user: user, pass: password)
        print("Calling URL: " + url);

        makeRequest(urlString: url, method: .post, responseHandler: responseHandler, errorHandler: errorHandler)
    }

    static func getAdOrderInfo(orderId: String, responseHandler: @escaping JsonResponseHandler,  errorHandler: @escaping ErrorHandler) {
        let url = UrlFactory.getAdOrderInfoUrl(orderId: orderId)
        print("Calling URL: " + url);

        makeRequest(urlString: url, method: .post, responseHandler: responseHandler, errorHandler: errorHandler)
    }

    static func getDetailedMusicChannels(responseHandler: @escaping JsonResponseHandler,  errorHandler: @escaping ErrorHandler) {
        let url = UrlFactory.getMusicChannelUrl()
        print("Calling URL: " + url);

        makeRequest(urlString: url, method: .post, responseHandler: responseHandler, errorHandler: errorHandler)
    }

    static func getTvChannels(responseHandler: @escaping JsonResponseHandler,  errorHandler: @escaping ErrorHandler) {
        let url = UrlFactory.getTvChannelUrl()
        print("Calling URL: " + url);

        makeRequest(urlString: url, method: .post, responseHandler: responseHandler, errorHandler: errorHandler)
    }

    static func makeRequest(urlString: String, method: HTTPMethod, responseHandler: @escaping JsonResponseHandler, errorHandler: @escaping ErrorHandler) {
        Alamofire.request(urlString, method: method).validate().responseString {response in
            switch response.result {
            case .success:
                responseHandler(response)
                break
            case .failure(let error):
                errorHandler(error)
                break
            }
        }
    }
}

In this example file the Alamofire import works but the first error message displayed in no class for type DataResponse.

Whenever, I add the Bridging Header File to project -> target -> Objective-C Briding Header the Vitamio library compiles; however, none of the classes added by my CocoaPods work.

If I remove the bridging header file the CocoaPods work but Vitamio does not.

Any help would be appreciated.

2
  • Is there a Pod repository for Vitamio? I'm not sure what you are trying to do with Podfile.
    – Ryan
    Nov 22, 2016 at 20:08
  • There is not a Pod repo for Vitamio
    – Adam W
    Nov 22, 2016 at 20:31

1 Answer 1

3

When you use "use_frameworks!" in the Podfile as you are, you don't need to import anything in the bridging header. Cocoapods is making frameworks for each of those pods for you, so you can just import them as if they were common frameworks directly on your swift file:

import Vitamio

The name might be different, as I don't know this particular library.

Edit: seems I misunderstood the problem a bit, waiting on more info.

11
  • Yeah. I read something to this effect, but don't quite understand it. Vitamio does not have a Podfile to import hence why it is still being done in the briding header file.
    – Adam W
    Nov 22, 2016 at 20:31
  • @AdamW can you post a sample swift file where pods stop working? Nov 22, 2016 at 20:34
  • Added the sample file
    – Adam W
    Nov 22, 2016 at 20:43
  • @AdamW what's the problem you're getting there? Alamofire won't import? Nov 22, 2016 at 20:46
  • The import works fine. But it does not recognize the class DataResponse
    – Adam W
    Nov 22, 2016 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.