IOS development uses XMPPFramework for instant communication (I), iosxmppframework
I will not go into details about the XMPP theory in this blog. How can we add the XMPP protocol to implement communication? Next we will introduce the basic knowledge of XMPP, so that we can implement Interconnected Communication. The preparation is to have the server to support the XMPP protocol, then register a test account through spark, and finally use the XMPP to communicate with our existing account and password. As for how to enable the server to support the XMPP protocol, how to register an account through Spark is not the topic of this blog. This blog mainly describes how to use the XMPP protocol in our App.
The content of today's blog is how to introduce XMPPFramework in the project, and connect and authenticate our account and password on the App. Well, let's just talk about it.
I. Introduction of XMPPFramework
1. to use XMPP to import the framework, we should also use CocoaPods to manage third-party class libraries. In the corresponding project, we should use CocoaPods to introduce XMPPFramework and add the corresponding version of XMPPFramework framework to the Profile, then update the pod and install it. The terminal is as follows:
1 // XMPP Data Stream 2 @ property (strong, nonatomic) XMPPStream * xmppStream; 3 4 5 // create xmppstream6 self. xmppStream = [[XMPPStream alloc] init];
2. When XMPPFramework is used as a delegate callback, you must implement the XMPPStreamDelegate protocol in the corresponding Controller and then implement the corresponding methods in the Protocol.
(1). In the Controller that uses XMPPStream, use the Application's delegate to obtain the xmppStream instance we created above. The Code is as follows:
1 // obtain the xmppSteam of the Application (obtained through the singleton in application) 2 UIApplication * application = [UIApplication sharedApplication]; 3 id delegate = [Application delegate]; 4 self. xmppStream = [delegate xmppStream]; 5 6 // registration callback 7 [self. xmppStream addDelegate: self delegateQueue: dispatch_get_main_queue ()];
(2) After obtaining the XMPP stream, you can connect to the server. The connection server is divided into three parts: splice XMPPJID, add JID to xmppStream, and connect to the server. The Code is as follows:
1 // connect to server 2-(void) xmppConnect 3 {4 // 1. create JID 5 XMPPJID * jid = [XMPPJID jidWithUser: @ "lizelusdut" domain: MY_DOMAIN resource: @ "iPhone"]; 6 7 // 2. add JID to xmppSteam 8 [self. xmppStream setMyJID: jid]; 9 10 // connection Server 11 NSError * error = nil; 12 [self. xmppStream connectWithTimeout: 10 error: & error]; 13 if (error) {14 NSLog (@ "connection error: % @", [error localizedDescription]); 15} 16}
(3) Implement the callback method after connecting to the server (authenticate the user password after connecting). The Code is as follows:
1 // callback after connection 2-(void) xmppStreamDidConnect :( XMPPStream *) sender 3 {4 // authentication username and password 5 NSError * error = nil after successful connection; 6 [self. xmppStream authenticateWithPassword :@"! @ # Admin "error: & error]; 7 if (error) {8 NSLog (@" authentication error: % @ ", [error localizedDescription]); 9} 10}
(4) The code for callback after successful authentication is as follows:
// Callback after successful authentication-(void) xmppStreamDidAuthenticate :( XMPPStream *) sender {NSLog (@ "Login successful ");}
(5) The method to be called after the authentication fails. The Code is as follows:
1 // callback 2-(void) xmppStream: sender didNotAuthenticate :( DDXMLElement *) error after successful authentication
3 {
4 NSLog (@ "Logon Failed ");
5}
I personally feel that a long blog article is not conducive to others' knowledge, so today's blog is so long. Today is to connect to the server and authenticate the user's identity. The blog content will be updated in the future until the two apps can communicate with each other. I hope you will continue to pay attention to it.
IOS development: how to use a password to encrypt the specified plaintext? Which of the following is the best Framework for DES or AES?
You can use the built-in encryption method in ios. Reference:
# Import <CommonCrypto/CommonDigest. h>
Details: www.cnblogs.com/..4.html
Easy to ask, difficult to answer, and easy to answer!
To run this application, you must first install one of the following versions of NET Framework: v4030319
Go to the Microsoft official website to download the NET Framework, which is also available on other websites. Just install it.