1.初始化

1.1 开发环境

平台

开发环境

备注

iOS 平台

iOS 9.0+

固件环境

对应平台AC54/56等系列视频类芯片

详情需要咨询固件开发人员

开发环境

Xcode 10.0+

最好使用最新版本

1.2.库导入

1.2.1 依赖库

重要

IJKMediaFramework.framework 为bilibili的一个开源视频播放库,在本项目中有做出部分的修改,详情可以fork到GitHub上的项目

GitHub IJKMediaFramework

  1. CFNetork.framework

  2. AudioToolbox.framework

  3. AVFoundation.framework

  4. CoreGraphics.framework

  5. CoreVideo.framework

  6. libbz2.tbd

  7. VideoToolbox.framework

  8. libz.tbd

  9. MobileCoreServices.framework

  10. OpenGLES.framework

  11. QuartzCore.framework

  12. libstdc++.tbd

  13. CoreMedia.framework

  14. UIKit.framework

1.2.2 导入库

LibDV16SDK.framework:本文档中着重对此框架进行接入介绍

重要

+ Capability 由于项目中可能出现需要用到WiFi相关信息,使用中可以在Xcode的 Signing&Capabilities 中添加相关权限

1.3.连接以及初始化

1.3.1 接入准备

  1. 让手机连接上设备的WiFi,设备此时需要处于AP模式。

  2. 需要访问同于局域网内的设备,则需要提前获取到设备的IP地址.

1.3.2 连接设备

连接设备以及控制命令相关的类是:JLCtpSender.h

1// 其中DV_TCP_ADDRESS以及DV_TCP_PORT,均在JLDV16SDK.h类中定义了宏,该宏定义下的DV_TCP_ADDRESS地址默认为:192。168.1.1
2[[JLCtpSender sharedInstanced] didConnectToAddress:DV_TCP_ADDRESS withPort:DV_TCP_PORT];
3//当设备IP地址是一个定制地址时,可通过以下方法进行设置
4[[JLDV16SDK shareInstanced] setTcpIp:@"192.168.80.80"];

1.3.3 初始化信息获取

在连接上了设备的socket之后,需要对其进行初始化信息的请求

 1//通过监听通知知悉已经成功接入设备:
 2[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appAccessOK:) name:DV_APP_ACCESS object:nil];
 3-(void)appAccessOK:(NSNotification *)note{
 4    //获取设备的AP信息
 5    [[JLCtpSender sharedInstanced] checkDeviceStatusWithTopic:DV_AP_SSID_INFO];
 6    NSString *urlPath = [NSString stringWithFormat:@"http://%@:8080/mnt/spiflash/res/dev_desc.txt",DV_TCP_ADDRESS];
 7    NSURL *url = [NSURL URLWithString:urlPath];
 8    NSURLRequest *request = [NSURLRequest requestWithURL:url];
 9    NSURLSessionDataTask *downloadTask = [afmanager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
10    if (error) {
11        NSLog(@"error:%d",error.code);
12    }else{
13        NSData *data = responseObject;
14        NSString *path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
15        path = [path stringByAppendingPathComponent:@"/DVConfig/dev_desc.txt"];
16        [DFFile createOn:NSLibraryDirectory MiddlePath:@"DVConfig" File:@"dev_desc.txt"];
17        [DFFile writeData:data fillFile:path];
18        NSString *p_path = [[NSBundle mainBundle] pathForResource:@"product_type" ofType:@"plist"];
19        NSArray *productArray = [NSArray arrayWithContentsOfFile:p_path];
20        NSDictionary *devDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
21        NSLog(@"dev_desc.txt download Succeed");
22        [downloadTask resume];
23    }
24}

重要

由于iPhone程序进入后台后,会处于一个挂起的状态,由于不确定socket的断开时机,这里的一般做法是,在程序进入后台时,就把CtpSocket断开,待应用回到前台时再去重新获取设备

 1- (void)applicationDidEnterBackground:(UIApplication *)application {
 2// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
 3// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
 4
 5//退到后台时,断开连接
 6[[JLCtpSender sharedInstanced] desConnectedCTP];
 7}
 8- (void)applicationDidBecomeActive:(UIApplication *)application {
 9// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
10//    [[JLDV16SDK shareInstanced] setTcpIp:[SDKLib GatewayIP]];
11//回到前台时,重新连接设备
12[[JLCtpSender sharedInstanced] didConnectToAddress:DV_TCP_ADDRESS withPort:DV_TCP_PORT];
13}