iOS CocoaPods - how to resolve “use of '@import' when modules are disabled” error?

前端 未结 3 516
情歌与酒
情歌与酒 2021-01-18 05:19

I\'m seeking how to resolve \"use of \'@import\' when modules are disabled\" when adding Google Analytics through cocoapods:

pod \'Google/Analytics\', \'~>         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 05:31

    I googled a lot, but hacked the solution for your problem myself. Cleaning the project, re-building etc. wasn't working for me.

    The solution is to wrap API into Cocoa Class, and use this class in your imports instead of original.

    1. Create class, for example APAnalyticsTracker, where AP supposed to be your common application prefix. Here you'll have two files: APAnalyticsTracker.m and APAnalyticsTracker.h
    2. Import #import in APAnalyticsTracker and wrap the original implementation like this (see Gist for more information): https://gist.github.com/vladignatyev/c240a1a4867b17894b10
    3. Use APAnalyticsTracker.h from .mm files freely.
    4. Remember to enable modules, see https://stackoverflow.com/a/33125158/882187 comment from @barrast

提交回复
热议问题