美文网首页57e60d08dc49tom
怎样在Swift项目中引入CommonCrypto库

怎样在Swift项目中引入CommonCrypto库

作者: ChiOS | 来源:发表于2017-04-04 19:32 被阅读1121次

    借助modulemap

    1.创建modulemap文件

    modulemap files
    module CCommonCrypto [system] {
        header "/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/CommonCrypto/CommonCrypto.h"
        export *
    }
    
    module CCommonCrypto [system] {
        header "/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h"
        export *
    }
    
    module CCommonCrypto [system] {
        header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h"
        export *
    }
    
    module CCommonCrypto [system] {
        header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h"
        export *
    }
    
    module CCommonCrypto [system] {
        header "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/CommonCrypto/CommonCrypto.h"
        export *
    }
    
    module CCommonCrypto [system] {
        header "/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/CommonCrypto/CommonCrypto.h"
        export *
    }
    
    module CCommonCrypto [system] {
        header "/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h"
        export *
    }
    

    2.将modulemap路径添加到Import Paths

    Import Paths

    3.导入头文件使用

    Usage


    tips:如何在pod中使用?

    在podspec中添加s.preserve_paths、s.pod_target_xcconfig

    s.preserve_paths = 'CocoaPods/**/*'
    s.pod_target_xcconfig = {
        'SWIFT_INCLUDE_PATHS[sdk=macosx*]'           => '$(PODS_ROOT)/JRString/CocoaPods/macosx',
        'SWIFT_INCLUDE_PATHS[sdk=iphoneos*]'         => '$(PODS_ROOT)/JRString/CocoaPods/iphoneos',
        'SWIFT_INCLUDE_PATHS[sdk=iphonesimulator*]'  => '$(PODS_ROOT)/JRString/CocoaPods/iphonesimulator',
        'SWIFT_INCLUDE_PATHS[sdk=appletvos*]'        => '$(PODS_ROOT)/JRString/CocoaPods/appletvos',
        'SWIFT_INCLUDE_PATHS[sdk=appletvsimulator*]' => '$(PODS_ROOT)/JRString/CocoaPods/appletvsimulator',
        'SWIFT_INCLUDE_PATHS[sdk=watchos*]'          => '$(PODS_ROOT)/JRString/CocoaPods/watchos',
        'SWIFT_INCLUDE_PATHS[sdk=watchsimulator*]'   => '$(PODS_ROOT)/JRString/CocoaPods/watchsimulator'
    }
    

    注意:pod lib lint 校验不会通过,提交时可跳过此步直接push

    参考链接:http://stackoverflow.com/questions/25248598/importing-commoncrypto-in-a-swift-framework/37125785#37125785

    相关文章

      网友评论

      • rain__bow__:问下 CommonCrypto是属于OC的库还是C的呀,swift中应该能直接调用C库的吧?
      • 哈哈哈士奇XHB:你这个工程是framework还是一般的target?

      本文标题:怎样在Swift项目中引入CommonCrypto库

      本文链接:https://www.haomeiwen.com/subject/uvfzottx.html