Getting started using XMPPFramework on iOS(官方)

官方文檔,非常經(jīng)典狞膘,暫時沒有時間翻譯,可以先看一下

Introduction

The project comes with a sample Xcode project demonstrating running XMPPFramework on iOS. You can find it in the Xcode/iPhoneXMPP folder. This is not designed to be a full fledged application. It simply serves to show the potential of the framework as well as providing a concrete example of using the code on the iOS platform. Feel free to play with the project, and browse the AppDelegate code. Keep in mind that this sample project only makes use of a small portion of available functionality.

When you're ready to add the XMPPFramework to your own iOS project, this page will provide detailed instructions. (You can also use the included iPhoneXMPP Xcode project as a reference.)

It's best to work step by step. Don't skip steps.

Step 1

Use source control to checkout the latest version of the project. The default branch contains the latest stable version of the code.

(We are moving towards a more structured repository with tagging. But bear with us for now.)

Step 2

The framework has several dependencies. You do NOT have to git clone them separately. They are all included when you clone XMPPFramework, within the Vendor folder. We are going to walk through each dependency step-by-step, ensuring your project complies at the end of each step.

The first dependency is CocoaLumberjack. This is the logging framework used throughout the project.

(More information about this logging framework can be found on the Intro to XMPPFramework page. Plus there is a ton of documentation available on Lumberjack's project page.)

(You don't need to separately clone CocoaLumberjack. It's included in the Vendor folder when you clone XMPPFramework.) Copy Vendor/CocoaLumberjack into your project, and add to your Xcode project.

Lumberjack doesn't have any sub-dependencies or special required frameworks.

Ensure your project compiles.

Step 3

The second dependency is CocoaAsyncSocket. This is the low-level networking code used by the framework.

(You don't need to separately clone CocoaAsyncSocket. It's included in the Vendor folder when you clone XMPPFramework.)Copy Vendor/CocoaAsyncSocket into your project, and add to your Xcode project.

This dependency requires you to add Apple's CFNetwork framework to your project. (In Xcode 4, go to Target -> Build Phases -> Link Binary With Libraries -> + -> Select CFNetwork from drop down list)

This dependency also requires Apple's Security framework. (In Xcode 4, go to Target -> Build Phases -> Link Binary With Libraries -> + -> Select Security from drop down list)

Ensure your project compiles.

Step 4

The third dependency is KissXML. Since Apple did not include the NSXML classes in iOS (NSXMLDocument, NSXMLElement, NSXMLNode), we use KissXML as a drop in replacement.

(You don't need to separately clone KissXML. It's included in the Vendor folder when you clone XMPPFramework.) Copy Vendor/KissXML into your project, and add to your Xcode project.

KissXML uses libxml2 internally. Follow these detailed instructions (with pictures) explaining how to properly add libxml2 to your Xcode project. After you have done so, ensure your project compiles.

Step 5

The fourth and final dependency is libidn. Add the following files to your project, and add to your Xcode project:

  • Vendor/libidn/idn-int.h
  • Vendor/libidn/stringprep.h
  • Vendor/libidn/libidn.a

The last file listed above (libidn.a) is a static library, compiled as a fat binary including many architectures (x86*64, i386, ppc, armv6, armv7). As a result, it is a rather large file (1.3 MB). But fear not! The compiler will extract only those architectures it needs. Additionally it will extract only the portions of the library that get used, which in our case is only tiny portion of the entire library. In other words, this library won't add any significant size to your application!

Note: The source code for libidn is included in the project. (libidn-1.15.tar.gz) Obviously you should NOT add this to your project.

Ensure your project compiles.

Step 6

Add the following folders to your project, and add to your Xcode project:

  • Authentication
  • Categories
  • Core
  • Utilities

In addition, add libresolv.dylib to your Xcode project. (In Xcode 4, go to Target -> Build Phases -> Link Binary With Libraries -> + -> Select libresolv.dylib from drop down list)

Ensure your project compiles.

And now you're ready to start using XMPPFramework in your project. The Intro to XMPPFramework page explains how to do this.

Common Installation Problems

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).

Extensions

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 <SystemConfiguration/SystemConfiguration.h>

Then one can deduce that they'll need to add the SystemConfiguration framework to their project.
Automatic Reference Counting (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.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末什乙,一起剝皮案震驚了整個濱河市挽封,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌臣镣,老刑警劉巖场仲,帶你破解...
    沈念sama閱讀 218,525評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異退疫,居然都是意外死亡渠缕,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,203評論 3 395
  • 文/潘曉璐 我一進店門褒繁,熙熙樓的掌柜王于貴愁眉苦臉地迎上來亦鳞,“玉大人,你說我怎么就攤上這事棒坏⊙嗖睿” “怎么了?”我有些...
    開封第一講書人閱讀 164,862評論 0 354
  • 文/不壞的土叔 我叫張陵坝冕,是天一觀的道長徒探。 經(jīng)常有香客問我,道長喂窟,這世上最難降的妖魔是什么测暗? 我笑而不...
    開封第一講書人閱讀 58,728評論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮磨澡,結(jié)果婚禮上碗啄,老公的妹妹穿的比我還像新娘。我一直安慰自己稳摄,他們只是感情好稚字,可當我...
    茶點故事閱讀 67,743評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般胆描。 火紅的嫁衣襯著肌膚如雪瘫想。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,590評論 1 305
  • 那天昌讲,我揣著相機與錄音国夜,去河邊找鬼。 笑死剧蚣,一個胖子當著我的面吹牛支竹,可吹牛的內(nèi)容都是我干的旋廷。 我是一名探鬼主播鸠按,決...
    沈念sama閱讀 40,330評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼饶碘!你這毒婦竟也來了目尖?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,244評論 0 276
  • 序言:老撾萬榮一對情侶失蹤扎运,失蹤者是張志新(化名)和其女友劉穎瑟曲,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體豪治,經(jīng)...
    沈念sama閱讀 45,693評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡洞拨,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,885評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了负拟。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片烦衣。...
    茶點故事閱讀 40,001評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖掩浙,靈堂內(nèi)的尸體忽然破棺而出花吟,到底是詐尸還是另有隱情,我是刑警寧澤厨姚,帶...
    沈念sama閱讀 35,723評論 5 346
  • 正文 年R本政府宣布衅澈,位于F島的核電站,受9級特大地震影響谬墙,放射性物質(zhì)發(fā)生泄漏今布。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,343評論 3 330
  • 文/蒙蒙 一拭抬、第九天 我趴在偏房一處隱蔽的房頂上張望险耀。 院中可真熱鬧,春花似錦玖喘、人聲如沸甩牺。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,919評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽贬派。三九已至急但,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間搞乏,已是汗流浹背波桩。 一陣腳步聲響...
    開封第一講書人閱讀 33,042評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留请敦,地道東北人镐躲。 一個月前我還...
    沈念sama閱讀 48,191評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像侍筛,于是被迫代替她去往敵國和親萤皂。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,955評論 2 355

推薦閱讀更多精彩內(nèi)容