在App和Cocoa Touch Framework目标中使用静态库 [英] Using static library in both App and Cocoa Touch Framework targets

查看:131
本文介绍了在App和Cocoa Touch Framework目标中使用静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在名为 MyApp 的iPad项目中创建了一个新的Cocoa Touch Framework目标,名为 MyAppCore ,目的是在其中放入一些常用代码。

I've created a new "Cocoa Touch Framework" target called MyAppCore in my iPad project called MyApp, with the intention of putting some common code in there. Overall it works great, however, I've encountered problems with adding the static library provided by Google Analytics.

我想要能够使用Google Analytics(分析),不仅仅是在Google Analytics(分析)提供的静态库中, 目标,但在 MyAppCore 目标中。为了创建两个目标,我必须使用libGoogleAnalyticsServices.a链接这两个目标。这看起来工作,但当我运行应用程序,日志被轰炸的消息像这样:

I want to be able to use Google Analytics not only in the MyApp target, but inside of the MyAppCore target as well. In order to make both targets build, I have to link both targets with libGoogleAnalyticsServices.a. That appears to work, but when I run the app, the log is bombarded with messages like these:

Class GAI is implemented in both /path/to/MyAppCore.framework/MyAppCore 
and /path/to/MyApp.app/MyApp.
One of the two will be used. Which one is undefined.

如何以成功的方式在两个目标之间共享Google Analytics(分析)?

How can I share Google Analytics between the two targets in a successful way?

推荐答案

我设法解决这个问题,通过创建一个包装器类的Google Analytics(这是非常方便的,有的,无论如何)MyAppCore目标。所有Google Analytics(分析)访问都将通过此封装。这样,直接使用Google Analytics(分析)的唯一目标是MyAppCore,因此我只需要将该目标与Google Analytics(分析)相关联。

I managed to solve this issue by creating a wrapper class for Google Analytics (which is pretty handy to have, anyways) in the MyAppCore target. All access to Google Analytics will go through this wrapper. That way the only target that will use Google Analytics directly is MyAppCore, so I only have to link that target with Google Analytics.

这不会解决基础的共享问题我的应用程序目标和一个Cocoa Touch框架之间的静态库,但为此目的它也工作得很好。

This does not solve the underlying issue of sharing static libraries between my app target and a Cocoa Touch Framework, but for this purpose it works just as well.

这篇关于在App和Cocoa Touch Framework目标中使用静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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