1.将libHM_hmsdk.a hm_sdk.h导入工程
2.添加CFNetwork.framework libstdc++.6.0.9.dylib
3.设置Bulid Setting
" Build Setting >> Architectures >>Architectures>>armv7 armv6
" Build Active Architecture -->Only ON
4.初始化SDK
在appDelegate.m文件我们要支持 C++,所以要把后缀改为appDelegate.mm 的形式,这样编译器就会识别在appDelegate.mm
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
//华迈监控
hm_sdk_init();
return YES;
}
#import "hm_sdk.h"
#import "PublicMethod.h"
#import "HMNodeObject.h"
#import "HMChannelObject.h"
#import "HMRecordVideoObject.h"
#import "HMAudioPlayer.h"
#import "define.h" // 这个也不能省略
[self listWithList];
[ProgressHUD show:@"正在登录,请耐心等待"];
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(xiancheng) object:nil];
// 启动
[thread start];
-(void)xiancheng
{
LOGIN_SERVER_INFO loginInfo ;
loginInfo.ip = [@"isee.qdyibu.com" UTF8String ];
loginInfo.port = 80;
// loginInfo.user = [@"test" UTF8String ];
loginInfo.user = [@"cuihuxinyuan" UTF8String ];
loginInfo.password = [@"123456" UTF8String ];
loginInfo.plat_type = "ios";
loginInfo.keep_time = 60;
loginInfo.hard_ver = "iPhone";
loginInfo.soft_ver = "";
char err[512] = {0};
hm_result result = hm_server_connect(&loginInfo, &server_Id,err,512);
NSString *errorStr = [NSString stringWithUTF8String:err];
NSLog(@"result:%0x",result);
NSLog(@"errorStr:%@",errorStr);
NSLog(@"server_id:%s",server_Id);
if ( result == HMEC_OK)
{
[ProgressHUD dismiss];
NSLog(@"连接服务器成功");
[self loginServerOperation];
}
else
{
[ProgressHUD dismiss];
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"登录失败" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show];
return;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)loginServerOperation{
hm_result deviceListResult = hm_server_get_device_list(server_Id);
NSLog(@"deviceListResult:%0x",deviceListResult);
if ( deviceListResult != HMEC_OK) {
return;
}
//getTime
uint64 time;
hm_server_get_time(server_Id, &time);
if (time < HMEC_OK) {
return;
}
NSLog(@"time:%llu",time);
//getUserInfo
P_USER_INFO userInfo;
hm_server_get_user_info(server_Id,&userInfo);
if (userInfo == NULL)
{
NSLog(@"获取用户信息失败,%s",userInfo->name);
return;
}
//getTransferInfo
if (userInfo->use_transfer_service != HMEC_OK)
{
if (hm_server_get_transfer_info(server_Id) != HMEC_OK)
{
NSLog(@"获取穿透信息失败");
return;
}
}
//test getTree;
if (hm_server_get_tree(server_Id, &tree_hd) != HMEC_OK)
{
NSLog(@"获取设备树失败");
return;
}
[self handleDeviceTree];
}
#pragma mark -处理设备树接口
- (void)handleDeviceTree{
if (tree_hd != NULL)
{
hm_server_get_root(tree_hd,&root);
if (root != NULL)
{
ZhinenganbaoVC *wuye = [[ZhinenganbaoVC alloc]init];
wuye.node = root;
wuye.listArr =arrList;
[self.navigationController pushViewController:wuye animated:YES];
}
}
}
- (void)listWithList
{
arrList =[[NSMutableArray alloc]init];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"html/text",@"text/json", @"text/html", @"text/plain",nil];
//你的接口地址
NSString *url=[NSString stringWithFormat:@"%@/camera/query",SERVE];
NSDictionary *parameter = @{
@"cid":@"14",
@"pagenum":@"1",
@"pagesize":@"100",
};
[manager POST:url parameters:parameter progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
NSLog(@"%@",dict);
if (dict) {
// if ([[dict objectForKey:@"result"] boolValue]) {
NSArray *arr =[[NSArray alloc]init];
arr =[dict objectForKey:@"content"];
for (int i=0; i<arr.count; i++) {
[arrList addObject:[NSString stringWithFormat:@"%@",[arr[i] objectForKey:@"name"]]];
NSLog(@"%@",arrList);
}
}
[ProgressHUD dismiss];
// }
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
}