iOS CocoaPods - 如何解决“@import”在模块被禁用时的使用“错误? [英] iOS CocoaPods - how to resolve "use of '@import' when modules are disabled" error?

查看:2950
本文介绍了iOS CocoaPods - 如何解决“@import”在模块被禁用时的使用“错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找当通过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.


  1. 创建类,例如 APAnalyticsTracker ,其中 AP 应该是您常用的应用程序前缀。您将有两个文件: APAnalyticsTracker.m APAnalyticsTracker.h

  2. APAnalyticsTracker 中导入 #import< Google / Analytics.h> ,然后包装原始实现更多信息): https://gist.github.com/vladignatyev/c240a1a4867b17894b10 li>
  3. 使用 APAnalyticsTracker.h .mm 档自由。

  4. 请记住要启用模块,请参见 http://stackoverflow.com/a/33125158/882187 评论来自@barrast

  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 <Google/Analytics.h> 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 http://stackoverflow.com/a/33125158/882187 comment from @barrast

这篇关于iOS CocoaPods - 如何解决“@import”在模块被禁用时的使用“错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆