2023年12月7日发(作者:)
开始在iOS上使用XMPPFramework框架
简介
在提供的Xcode示例项目中,包含有在iOS中使用XMPPFramework的演示项目。您可以在Xcode/iPhoneXMPP文件夹中找到它。该项目的设计并不是为了演示一个完整的商业应用,而仅是为了演示如何使用XMPPFramework框架,并提供有iOS平台上需要使用的具体代码。您可以随意修改及测试该项目,并浏览AppDelegate文件中的代码。提示,该示例程序仅使用了框架中的一小部分功能。
本文档提供了如何将XMPPFramework框架添加到iOS项目的详细说明,您也可以参照iPhoneXMPP项目中的具体引用。
提示:请按照以下步骤逐一执行,而不要省略或者跳过某个步骤。
第一步
使用源代码管理器检出最新版本的项目。默认的分支包含有最新稳定版本的代码。
第二步
尽管本框架包含有对其他项目的依赖,不过您已无需再使用git去分别克隆这些项目。在克隆XMPPFramework框架的同时,这些项目会被同时克隆并保存在Vendor文件夹中。接下来,我们将逐一确认每一个依赖,以确保在完成最后一步工作之后,能够正常编译项目。
第一个依赖是CocoaLumberjack,这是XMPPFramework框架使用的日志框架。
(有关日志框架的进一步信息,可以参见XMPPFramework的介绍文档,另外在Lumberjack的项目主页中也提供有大量的文档。)
将Vendor/CocoaLumberjack复制并添加入Xcode项目。
Lumberjack不包含任何子依赖或特殊要求的框架。
现在,请确认您的项目可以正常编译。
第三步
第二个依赖是CocoaAsyncSocket,这是XMPPFramework框架使用的底层网络框架。
将Vendor/CocoaAsyncSocket复制并添加入Xcode项目。
要使用此依赖,需要将苹果的CFNetwork框架添加到项目。(在Xcode 4中,选择Target -> Build Phases -> Link Binary With Libraries -> + ->并从弹出的下拉列表中选择CFNetwork框架)
要使用此依赖,还需要将苹果的Security框架添加到项目。(在Xcode 4中,选择Target -> Build Phases -> Link Binary With Libraries -> + ->从弹出的下拉列表中选择Security框架)
现在,请确认您的项目可以正常编译。
第四步
第三个依赖是KissXML,由于苹果并没有针对iOS提供NSXML类以处理NSXMLDocument、NSXMLElement、NSXMLNode,因此我们使用KissXML取而代之。
将Vendor/KissXML复制并添加入Xcode项目。
由于KissXML内部使用到libxml2。因此还需要告诉Xcode在哪里可以找到libxml2的头文件,并且在编译完成后链接libxml2编译库。要做到这两点,在项目的编译设置中设置以下两条编译指令即可:
1. OTHER_LDFLAGS = -lxml2
2. HEADER_SEARCH_PATHS = /usr/include/libxml2
执行完上述操作后,请确认您的项目可以正常编译。
第五步
第四个以及最后一个依赖是libidn。将以下文件添加到项目中:
Vendor/libidn/idn-int.h
Vendor/libidn/stringprep.h
Vendor/libidn/libidn.a
上述最后一个文件libidn.a是一个静态库,支持包括:x86*64、i386、ppc、armv6、armv7等多种架构。因而该文件的个头也不小,大约有1.7M。但是不用担心,编译器会在编译时仅提取架构所需的内容,并且只会提取被使用的那一部分,而由于框架中仅仅只用到了该静态库中很小的一部分内容。换言之,该静态库的使用不会明显增加您应用程序的大小!
注释:libidn的源代码包含在中。不过很显然,没有必要将其添加到项目之中。
执行完上述操作后,请确认您的项目可以正常编译。
第六步
将以下文件夹复制并添加入Xcode项目:
Authentication
Categories Core
Utilities
另外,还需将添加至Xcode项目。(在Xcode 4中,选择Target ->
Build Phases -> Link Binary With Libraries -> + ->从弹出的下拉列表中选择)
执行完上述操作后,请确认您的项目可以正常编译。
至此,您已经准备好在项目中使用XMPPFramework框架了。后续的相关操作请参见:Intro to XMPPFramework文档。
常见安装问题
In XCode 4.2.1 (and perhaps other versions), following these directions will allow
a bare bones project to compile. However, upon importing an XMPPFramework
class, such as by calling '#import XMPP.h' will cause XCode to show an error
'XMPP.h' not found. It appears that XCode is not finding any of the
XMPPFramework files.
The fix for this is to make sure that you DID NOT just drag and drop the
XMPPFramework files into your project. Notice in this wiki is says to copy the
files into your project folder, and then add the files into your project. So, if your
XCode project is called XMPPTest, there will be an XMPPTest folder wherever you
created your project, as in /Users/johndoe/XMPPTest. Taking step 2 for example,
you need to press the "option" key and drag the folder titled "CocoaLumberjack"
into /Users/johndoe/XMPPTest. THEN you can drag the "CocoaLumberjack"
folder inside /Users/johndoe/XMPPTest into your actual XCode project. When
you do, you should be sure to check the box "Copy items into destination's group
folder (if needed) and select the radio button "Create folder references for any
added folders". You should make sure that the checkboxes inside the "Add to
targets" box are checked.
If you do not do this, XMPPFramework will not be functional.
In XCode 4.6.1, using iOS SDK 6.1, XMPPFramework was not functional when I
imported using folder references. I had to use groups to get things working.
In some cases, you may need to also add the file libxml2 by clicking on your
target->build phases-> link binary with libraries -> click on the "+" sign ->
libxml2.2.7.3dylib
When you see mach linker errors, make sure you have added the security
framework (which is not mentioned in the tutorial).
扩展
Keep in mind that various optional extensions may have other requirements. For
example, core data storage classes are obviously going to require the CoreData framework. If you add an optional extension to your project, and you get linker
errors, then take a look at the various #imports in the header and
implementation files within the extension that you added. If you see something
like this:
#import
Then one can deduce that they'll need to add the SystemConfiguration
framework to their project.
ARC
The latest versions of XMPPFramework use ARC. If you're not using ARC in your
project, learn how to properly flag the XMPPFramework files as ARC in your
Xcode project on the ARC page.
If still ARC-related issues persist, make sure you removed the Facebook
integration.
问题
If you have questions concerning XMPPFramework, feel free to make use of the
XMPPFramework Mailing List.


发布评论