连接
版本/作者/日期 | 修改内容 |
---|---|
1.0/Sandy/2015-09-24 | 初版 |
3.连接
条件:sdk初始化成功
语法:
1)函数
-(int)smartConnect:(BOOL)autoRetry retryInterval:(int)retry_sec;//智能连接,根据自身属性和网络状况自动选择连接方式 参数:(BOOL)autoRetry:是否自动重连接 (int)retry_sec:重连间隔时间 -(int)connect:(IPCamera_CONNECT_TYPE)connectType autoRetry:(BOOL)autoRetry retryInterval:(NSUInteger)retry_sec;//指定类型连接摄像机 参数:(IPCamera_CONNECT_TYPE)connectType:连接类型 CONNECT_TYPE_UNKNOWN = -1, CONNECT_TYPE_LAN = 0, //局域网直连 CONNECT_TYPE_P2P = 2, //P2P方式 CONNECT_TYPE_DDNS = 3, //DDNS方式直连 (BOOL)autoRetry:是否自动重连接 (int)retry_sec:重连间隔时间 -(void)disconnect; //断开连接
2)消息
FOUNDATION_EXPORT NSString* const IPCamera_Connect_Status_Changed_Notification;
3)消息回调函数
-(void)IPCamera_response_function:(NSNotification*)note;
IPCamera.h宏定义了两种注册消息的方法
#define ADD_IPCAMERA_RESPONSE_WITHOUT_ARG(notice_name) \ [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(IPCamera_response_function:) name: notice_name object: nil] #define ADD_IPCAMERA_RESPONSE_WITH_ARG(notice_name,camera_object) \ [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(IPCamera_response_function:) name: notice_name object: camera_object]
示列
1)连接
方法一:局域网连接
//创建一个cam+注册消息 IPCamera * cam_ = [[IPCamera alloc]init]; ADD_IPCAMERA_RESPONSE_WITH_ARG( IPCamera_Connect_Status_Changed_Notification, cam_) //cam的属性参数 cam_.ID; //ID cam_.host;//IP cam_.port; //端口 cam_.user; //用户名 cam_.pwd; //密码 cam_.ssl; //是否加密传输 ,1是0否 [cam_ connect:CONNECT_TYPE_LAN autoRetry:YES retryInterval:10.0];
- 方法二:p2p连接
//创建一个cam+注册消息 IPCamera * cam_ = [[IPCamera alloc]init]; ADD_IPCAMERA_RESPONSE_WITH_ARG( IPCamera_Connect_Status_Changed_Notification, cam_) //cam的属性参数 cam_.ID; //ID cam_.user; //用户名 cam_.pwd; //密码 cam_.ssl; //是否加密传输 ,1是0否 [cam_ connect:CONNECT_TYPE_P2P autoRetry:YES retryInterval:10.0];
- 方法三:智能连接+注册消息
//创建一个cam IPCamera * cam_ = [[IPCamera alloc]init]; ADD_IPCAMERA_RESPONSE_WITH_ARG( IPCamera_Connect_Status_Changed_Notification, cam_) //获取cam的属性参数 cam_.ID; //ID cam_.user; //用户名 cam_.pwd; //密码 cam_.ssl; //是否加密传输 ,1是0否 cam_.port; //端口 局域网直连时:self.port;P2P连接时: self.currentP2PPort; cam_.host; //ip 局域网直连时:是self.host; P2P连接时:是127.0.0.1 //连接 [item smartConnect: YES retryInterval: 10.0 ];
2)消息回调
-(void)IPCamera_response_function:(NSNotification*)note { if( [note.name isEqualToString:IPCamera_Connect_Status_Changed_Notification ]) { NSLog(@"连接发生改变改变"); } }
3)断开连接
[cam_ disconnect];