【三分鐘教程】便於使用XMPP實現iOS單聊教程(附源碼)

來源:互聯網
上載者:User

標籤:des   style   c   class   blog   ext   

 

編號 需要修改的代碼
1 //
//  Prefix header
//
//  The contents of this file are implicitly included at the beginning of every source file.
//

#import <Availability.h>
//伺服器IP
#define kXMPPHost @"115.29.222.253"
//伺服器連接埠
#define kHostPort 5222
//伺服器名稱,也是使用者名稱尾碼
#define kHostName @"paxy.com.cn"
2 //
//
//  AppDelegate.m
//  企信通
//
//  Created by chenyilong on 14-3-3.
//  Copyright (c) 2014年 部落格地址: http://www.cnblogs.com/ChenYilong. All rights reserved.
//
- (void)connect
{
    
// 2. 從系統偏好讀取使用者資訊
    
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//    NSString *hostName = [defaults stringForKey:kXMPPLoginHostNameKey];
    
NSString *hostName = kHostName;
    
NSString *userName = [defaults stringForKey:kXMPPLoginUserNameKey];
    
// 如果使用者名稱或者主機為空白,不再繼續
//    if (hostName.length == 0 || userName.length == 0) {
        
if ( userName.length == 0) {

        
// 使用者名稱和主機都為空白說明使用者沒有登入,通常是第一次運行程式
        
// 直接顯示登入視窗
        [
self showStoryboardWithBoardName:kLoginStoryboardName];
        
        
return;
    }
    [
_xmppStream setHostName:kXMPPHost];
[_xmppStream setHostPort:kHostPort];
    _xmppStream.myJID = [XMPPJID jidWithUser:userName domain:hostName resource:nil];
    // 串連
    // GCDAsnycSocket架構中,所有的網路通訊都是非同步
    NSError *error = nil;
    if (![_xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) {
        DDLogInfo(@"%@", error.localizedDescription);
    } else {
        DDLogInfo(@"發送串連請求成功");
    }
}

3 伺服器搭建教程:http://www.cnblogs.com/ChenYilong/p/3587344.html 基本程式介紹(使用者登入介面)教程:http://www.cnblogs.com/ChenYilong/p/3587335.html 官方demo: iPhoneXMPP.zip
54.0 KB

如需協助,[email protected]交流,朝九晚五之外(工作時間之外)才登該QQ  



   

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.