iOS CocoaPods - 如何解决“@import”在模块被禁用时的使用“错误? [英] iOS CocoaPods - how to resolve "use of '@import' when modules are disabled" error?
问题描述
我正在寻找当通过cocoapods添加Google Analytics(分析)时如何解决@import在模块被禁用时的使用:
I'm seeking how to resolve "use of '@import' when modules are disabled" when adding Google Analytics through cocoapods:
pod 'Google/Analytics', '~> 1.0.0'
link_with 'AppTarget', 'AppTargetTests'
p>
In code:
#import <Google/Analytics.h>
我在pod中收到此错误:
I get this error within a pod:
"use of '@import' when modules are disabled"
我检查了所有项目,看到模块已启用,以及其他建议自动链接框架
I checked all projects and see that modules are enabled, along with the other suggestiont to "Link frameworks automatically"
我无法覆盖此导入,因为此错误:
I cannot override this import because of this error:
当xCode6中通过cocoapods添加框架时,如何禁用模块@import?
推荐答案
我googled了很多,但黑客自己的问题的解决方案。清理项目,重建等对我来说不起作用。
I googled a lot, but hacked the solution for your problem myself. Cleaning the project, re-building etc. wasn't working for me.
解决方案是将API包装到Cocoa类中,并在导入中使用此类,而不是
The solution is to wrap API into Cocoa Class, and use this class in your imports instead of original.
- 创建类,例如
APAnalyticsTracker
,其中AP
应该是您常用的应用程序前缀。您将有两个文件:APAnalyticsTracker.m
和APAnalyticsTracker.h
- 在
APAnalyticsTracker
中导入#import< Google / Analytics.h>
,然后包装原始实现更多信息): https://gist.github.com/vladignatyev/c240a1a4867b17894b10 li>
- 使用
APAnalyticsTracker.h
从.mm
档自由。 - 请记住要启用模块,请参见 http://stackoverflow.com/a/33125158/882187 评论来自@barrast
- Create class, for example
APAnalyticsTracker
, whereAP
supposed to be your common application prefix. Here you'll have two files:APAnalyticsTracker.m
andAPAnalyticsTracker.h
- Import
#import <Google/Analytics.h>
inAPAnalyticsTracker
and wrap the original implementation like this (see Gist for more information): https://gist.github.com/vladignatyev/c240a1a4867b17894b10 - Use
APAnalyticsTracker.h
from.mm
files freely. - Remember to enable modules, see http://stackoverflow.com/a/33125158/882187 comment from @barrast
这篇关于iOS CocoaPods - 如何解决“@import”在模块被禁用时的使用“错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!