I hope that this is a new day!
Before I look at the code, I think you should tidy up your mood and listen to my words:
First of all, I hope you read this blog in the morning, and then start the operation, assuming that you just look at the blog and do not go to their own control of the project, the role is not very large. Set off, so with a desire for technology, excited. The excitement of the mood to learn. You have the talent to gain.
Well, I'll take the first thing I get up every morning when I'm doing the project. is to study the code of Xmppframework author, analyze and imitate the writing according to the module. Sleep time is still thinking, analysis. Summarize...
Of course I'm not saying that every dev has to do this to me, just that you can keep a positive attitude towards technology and your work.
That's all.
Resourceurl:https://github.com/robbiehanson/xmppframework (Let's say you're still maintaining your existing XMPP-based products.) Then you need to sometimes to see if the original author fix some bugs)
Iphonexmpp Demo
1.appdelegate.m
A. Probably look at the head file. OK, do not jump in-depth, the following I will teach high-speed look. See this method
There are several places to be aware of:
1) Ddlog used not to insist, I like a clean and refreshing console. So it's useless, because I'm not very dependent on all the logs. Instead of breakpoint console po xxx method, real-time to find problems fixing bugs
2) Configure the XML stream stream to add a variety of buff to your long connection. Various equipment, various properties. OK, no kidding:), this configuration is very important, it determines which XMPP service your app needs to support, which determines the original author (C.H. Robinson) which code function module is not required to take effect
3) Start the connection and of course there is a cancel connect
B Set your XML Stream. What features are turned on
-(void) Setupstream{nsassert (Xmppstream = = nil, @ "Method Setupstream invoked multiple times");//Setup XMPP stream////Th E Xmppstream is the base class for all activity.//everything else plugs into the xmppstream, such as Modules/extensions a nd delegates.xmppstream = [[Xmppstream alloc] init]; #if! target_iphone_simulator{//want XMPP to run in the background?P.S.-the simulator doesn ' t support backgrounding yet.//If you try to set the associated property on the Simulator, it simply fails.//and when you background a app on the simulator,//it just queues network Traf Fic til the app is foregrounded again.//We be patiently waiting for a fix from apple.//If you do Enableba Ckgroundingonsocket on the simulator,//you'll simply see a error message from the XMPP stack when it fails to s ET the Property.<span style= "color: #66ff99;" >xmppstream.enablebackgroundingonsocket = Yes;</span>} #endif//Setup reconnect////The Xmppreconnect module Monitors for "accidental disconnections" and//automatically reconnects the stream for you.//there ' s a bunch more Informa tion in the xmppreconnect header file.xmppreconnect = [[Xmppreconnect alloc] init];//Setup roster////The Xmpproster Han DLEs the XMPP protocol stuff related to the roster.//the storage for the roster are abstracted.//so you can use any storage mechanism your want.//you can store it all in memory, or use the core data and store it on disk, or use Core data with a in-memory store,//or setup your own using raw SQLite, or create your own storage mechanism.//you can D O It however you like! It's your application.//but you did need to provide the roster with some storage facility.xmpprosterstorage = [[Xmpproster Coredatastorage alloc] Init];//xmpprosterstorage = [[Xmpprostercoredatastorage alloc] initwithinmemorystore]; Xmpproster = [[Xmpproster alloc] initwithrosterstorage:xmpprosterstorage];xmpproster.autofetchroster = YES; xmpproster.autoacceptknownpresencesubscriptionrequests = yes;//Setup vCard support////The vcard Avatar module works in Conjuction with the standard vCard Temp module to download user avatars.//the xmpproster would automatically integrate wit H Xmppvcardavatarmodule to cache roster photos in the Roster.xmppvcardstorage = [Xmppvcardcoredatastorage sharedinstance] ; xmppvcardtempmodule = [[XMPPVCardtempmodule alloc] Initwithvcardstorage:xmppvcardstorage];xmppvcardavatarmodule = [[Xmppvcardavatarmodule alloc] initwithvcardtempmodule:xmppvcardtempmodule];</span>//Setup capabilities////The Xmppcapabilities module Handles all the complex hashing of the Caps Protocol (XEP-0115).//Basically, when other clients broadcast their presence On the network//they include information about what capabilities their client supports (audio, video, file transfer, etc) .//But as can imagine, this list starts to get pretty big.//this is where the hashing stuff comes into play.//most People running the same version of the same client is going to has the same list of capabilities.//so the protocol Defi NES a standardized-to-hash the list of capabilities.//clients then broadcast the tiny hash instead of the big list.// The Xmppcapabilities protocol automatically handles figuring out what these hashes mean,//and also persistently storing The hashes so lookups aren ' t needed inThe future.////similarly to the roster, the storage of the module was abstracted.//you be strongly encouraged to Persis T caps information across sessions.////The Xmppcapabilitiescoredatastorage is a ideal solution.//It can also be shared Amongst multiple streams to further reduce hash lookups.xmppcapabilitiesstorage = [Xmppcapabilitiescoredatastorage Share Dinstance]; Xmppcapabilities = [[Xmppcapabilities alloc] initwithcapabilitiesstorage:xmppcapabilitiesstorage]; Xmppcapabilities.autofetchhashedcapabilities = YES; Xmppcapabilities.autofetchnonhashedcapabilities = no;//Activate xmpp modules[xmppreconnect activate:xmppstream];[ Xmpproster Activate:xmppstream]; [Xmppvcardtempmodule Activate:xmppstream]; [Xmppvcardavatarmodule Activate:xmppstream]; [Xmppcapabilities activate:xmppstream];//Add ourself as a delegate to anything we'll be interested In[xmppstream ad Ddelegate:self Delegatequeue:dispatch_get_main_queue ()]; [Xmpproster adddelegate:self delEgatequeue:dispatch_get_main_queue ()];//optional:////Replace me with the proper domain and port.//The example below is Setup for a typical Google Talk account.////If you don ' t supply a hostName and then it'll be automatically resolved Usin G The JID (below)./For example, if you supply a JID like ' [email protected]/rsrc '//Then the XMPP framework would fo Llow the XMPP specification, and do a SRV lookup for quack.com.////If you don ' t specify a hostport, then the default (52 () 'll be Used.//[xmppstream sethostname:@ "talk.google.com"];//[xmppstream sethostport:5222];//, need to alter t hese settings Depending on the server you ' re connecting tocustomcertevaluation = YES;}
Ok,let ' s begin.
1) Create an XML stream object. What is this stuff for? Make a metaphor: freight transport belt. Both the cargo and the annealed depend on the tape. Who let this tape move?
Long connections
It's a motor.
So what's in the goods? 3 Kinds of goods: American version. Hong Kong version. Japanese version, occasionally with a little country line. (*^__^*) hehe ..., haha no kidding. There are three kinds of goods:<iq> <p><message>, occasionally with some other labels <a><r> something.
Sodasne!
~ KO One! ~ Yes, good, great! ~ Found yesterday RFC6121 a bit of a relationship. ~\ (≧▽≦)/~ la La.
2) whether to turn on background mode---NO. Unless you have VoIP need to support, otherwise endless, now GitHub on the backstage issue another big pile of unresolved, anyway it is very complex. I didn't support this stuff.
<span style= "color: #66ff99;" >xmppStream.enableBackgroundingOnSocket</span>
3) Turn on the reconnection mechanism (long connection necessary, heartbeat what)
Turn on roster (two forms: CoreData storage or open memory-temporary object storage), take the initiative to get the roster data on the server? Whether to voluntarily answer the subscription request that already exists for the small partner who subscribed to the presence message. This means whether or not you proactively filter out subscribed subscriptions or user requests that have formed a subscription relationship. later chapters). Open roster Coredatastorage, which is the data inventory coredata storage technology.
Open the vcard (personal information details) module. Two-time Package vcard module on, and start vcard corresponding CoreData storage technology
Open the Capabilitie, and the storage technology with it. The goods had been looked at for a long time. But now I've forgotten.
。。 Sorry, this piece needs to find the corresponding XEP to carry on the brain to mend, just seemingly temporarily cannot use. Let it go by default.
Original link Portal
The following is a core of xmppframework: Multi Delegate (author exclusive. Worship!
~
[Xmppstream adddelegate:self Delegatequeue:dispatch_get_main_queue ()]; [Xmpproster adddelegate:self Delegatequeue:dispatch_get_main_queue ()];
Adds a sub delegate callback to the XML stream, at the current class. In the Mainthread queue,
A sub delegate callback is made to the roster, in the current class, the main thread queue.
About multi delegate technology. Suggest a good look inside the detailed realization. Do not ask you to write, probably the core thought can be understood, will return BOOL YES or NO can be.
。
。
BTW1: My humble worship to this multi delegate again. Of course he wrote a lot of things. It's all for me to worship.
For example, the socket link ...
XML parsing. Ddlog.
。 Anyway, a lot of good, not to say. Said more are tears, vegetable dogs can only look at the great God.
BTW2: Brush brushes Two hours passed, wash and sleep, write blog really very tired.
Btw3:server that water? ask you about it. Do you have a good environment? No, I'm going to example a test connection here. Give an account and password. Labour efficiency is so high. One day to fix the main data connection.
BTW4: Manager, my side is still smooth, about small into, you see this connection interface, became, although the interface ugly point, but can connect on the service side, awesome.
BTW5: PA! You're a jerk. Do not say this to the demo, how to have your teammates.
BTW6: Next preview <ios xmppframework--im underlying architecture design + Technical Preparation >
XMPP protocol for Instant Messaging underlying writing (ii)--IOS xmppframework demo+ Analysis