iOS开发 东芝WifiSD卡 读取单反相机照片

iOS开发 东芝WifiSD卡 读取单反相机照片

因项目中需要读取东芝wifiSDcard中的图片,结合网上的资料 写出了一下Demo 做下记录

#import 

NS_ASSUME_NONNULL_BEGIN

@interface VZWifiSDCardImage : NSObject
@property (nonatomic,copy) NSString *imagePath;        //图片地址
@property (nonatomic,copy) NSString *imageName;        //图片名称
@end


@interface VZWifiSDCardFolder : NSObject
@property (nonatomic,copy) NSString *folderName;        //文件名称
@property (nonatomic,strong) NSMutableArray *floderimages;        //文件夹下的图片
@end

@interface VZWifiSDCardImageManager : NSObject
//获取东芝WifiSDcard上面的图片内容
+(NSMutableArray *)getImagesForWifiSDCard;
@end

NS_ASSUME_NONNULL_END

#import "VZWifiSDCardImage.h"

@implementation VZWifiSDCardImage

@end

@implementation VZWifiSDCardFolder

@end

@implementation VZWifiSDCardImageManager
+(NSArray *)getImagesForWifiSDCard{
    NSString *baseURL = @"http://192.168.0.1/command.cgi?op=100&DIR=/DCIM";
    NSString *basePath =  @"http://192.168.0.1/DCIM";
    NSURL *allData = [NSURL URLWithString:baseURL];
    //以字符串的状态读出来DCIM的文件夹下的所有内容
    NSString *stringOfFilesICDCIM = [NSString stringWithContentsOfURL:allData encoding:NSUTF8StringEncoding error:NULL];
    //获得DCIM下所有的文件夹
    NSArray *array_files = [stringOfFilesICDCIM componentsSeparatedByString:@"\r\n"];
   
    //提前声明。
    NSMutableArray   *folderArray = [[NSMutableArray alloc]init];
    //分别遍历各个文件夹。
    [array_files enumerateObjectsUsingBlock:^(NSString *  _Nonnull obj_folderNmae, NSUInteger idx, BOOL * _Nonnull stop) {
        //筛选符合条件的进行遍历
        BOOL eligible =  [self returnBOOLValueWithString:obj_folderNmae];
        if (eligible) {
            //再分别筛选他们的字段。
            NSArray *array_atts = [obj_folderNmae componentsSeparatedByString:@","];
            //文件夹名称就是第2个字段。
            NSLog(@"%@/%@",array_atts.firstObject,array_atts[1]);
            //进行存储文件夹的名字
            VZWifiSDCardFolder *folder = [[VZWifiSDCardFolder alloc]init];
            folder.folderName = array_atts [1]; // 100CANON 文件夹的名字。。。。。。
            //再次遍历取出该文件夹下的文件路径。。。(二级路径);
            NSURL *urlForFolderInfo = [NSURL URLWithString:[baseURL stringByAppendingPathComponent:folder.folderName]];
            
            //取出该文件夹下的文件路径
            NSString *imageDCIM = [NSString stringWithContentsOfURL:urlForFolderInfo encoding:NSUTF8StringEncoding error:NULL];
            NSArray *array_image = [imageDCIM componentsSeparatedByString:@"\r\n"];
            folder.floderimages = [[NSMutableArray alloc]init];
            [array_image enumerateObjectsUsingBlock:^(NSString *  _Nonnull obj_image, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([self returnBOOLTwoWithString:obj_image]) {
                    //取得文件的名称
                    NSArray *VZimages = [obj_image componentsSeparatedByString:@","];
                    VZWifiSDCardImage *image = [[VZWifiSDCardImage alloc] init];
                    image.imageName = VZimages[1];
                    image.imagePath = [basePath stringByAppendingFormat:@"/%@/%@", folder.folderName, image.imageName];
                    [folder.floderimages addObject:image];
                }
                
            }];

            if (folder.folderName != nil) {
                [folderArray addObject:folder];
            }
        }
        
    }];
    
    return folderArray;
    

}

+(BOOL)returnBOOLValueWithString:(NSString *)folderName{
    if (folderName.length > 0 && ![folderName containsString:@"WLAN"] && ![folderName containsString:@".JPG"] && ![folderName containsString:@"TSB"] &&  ![folderName containsString:@"EOSMISC"]) {
        return YES;
    }
    return NO;
}

+(BOOL)returnBOOLTwoWithString:(NSString *)stringOfImageAttributes{
    if (stringOfImageAttributes.length > 0 && ![stringOfImageAttributes containsString:@"WLAN"] && [stringOfImageAttributes.uppercaseString containsString:@".JPG"]) {
        return YES;
    }
    return NO;
}

@end

在ViewController里面的内容

#import "ViewController.h"
#import "XJTableViewCell.h"
#import 
#import "VZWifiSDCardImage.h"

@interface ViewController ()
@property (nonatomic,strong) UITableView *tableView;        //表格视图
@property (nonatomic,strong) NSMutableArray *arrayOfFoldersWithImagesInFlashair;        //照片信息
@end
@implementation ViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass(XJTableViewCell.class) bundle:nil] forCellReuseIdentifier:NSStringFromClass(XJTableViewCell.class)];
    self.tableView.rowHeight = 100;
    
    [self getData];
   

   
}


-(void)getData{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        
        self.arrayOfFoldersWithImagesInFlashair = [VZWifiSDCardImageManager getImagesForWifiSDCard];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//            [self getData];
//        });
    });
   
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    XJTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(XJTableViewCell.class)];
    VZWifiSDCardImage * modele = self.arrayOfFoldersWithImagesInFlashair[indexPath.section].floderimages[indexPath.row];
    
    [cell.icon sd_setImageWithURL:[NSURL URLWithString:modele.imagePath] placeholderImage:nil];
    cell.imageName.text = modele.imageName;
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arrayOfFoldersWithImagesInFlashair[section].floderimages.count;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.arrayOfFoldersWithImagesInFlashair.count;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return self.arrayOfFoldersWithImagesInFlashair[section].folderName;
}


-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
@end

另附上在网上搜索到的资源

功能 执行的HTTP GET请求命令参数示例
获取文件列表 http://flashair/command.cgi?op=100&DIR=/ DCIM
获取的文件数量 http://flashair/command.cgi?op=101&DIR=/ DCIM
获取更新状态 http://flashair/command.cgi?op=102
获取SSID http://flashair/command.cgi?op=104
获取网络密码 http://flashair/command.cgi?op=105
获取MAC地址 http://flashair/command.cgi?op=106
设置浏览器语言 http://flashair/command.cgi?op=107
获取固件版本 http://flashair/command.cgi?op=108
获取控制图像 http://flashair/command.cgi?op=109
获取无线局域网模式 http://flashair/command.cgi?op=110
设置无线局域网超时长度 http://flashair/command.cgi?op=111
获取应用程序的唯一信息 http://flashair/command.cgi?op=117
获取CID http://flashair/command.cgi?op=120
获取从共享内存中的数据 http://flashair/command.cgi?op=130&ADDR=0&LEN=8
设置数据共享内存 http://flashair/command.cgi?op=131&ADDR=0&LEN=8&DATA=0123ABCD
获取空扇区数 http://flashair/command.cgi?op=140
让照片分享模式 http://flashair/command.cgi?op=200&DIR=/ DCIM/100__TSB&DATE=17153
禁用的照片分享方式 http://flashair/command.cgi?op=201
获取的照片分享模式状态 http://flashair/command.cgi?op=202
获取SSID的照片分享方式 http://flashair/command.cgi?op=203
获取缩略图 http://flashair/thumbnail.cgi?/DCIM/100__TSB/DSC_100.JPG
设置连接超时 http://flashair/config.cgi?MASTERCODE=0123456789AB&APPAUTOTIME=3000000&APPMODE=4
设置应用程序的唯一信息 http://flashair/config.cgi?MASTERCODE=0123456789AB&APPINFO=0123ABCD4567EFGH
设置无线局域网模式 http://flashair/config.cgi?MASTERCODE=0123456789AB&APPMODE=4
设置网络安全密钥 http://flashair/config.cgi?MASTERCODE=0123456789AB&APPNETWORKKEY=12345678
设置的SSID http://flashair/config.cgi?MASTERCODE=0123456789AB&APPSSID=flashair
设置网络安全密钥互联网直通模式 http://flashair/config.cgi?MASTERCODE=0123456789AB&BRGNETWORKKEY=12345678
设置SSID的网络直通模式 http://flashair/config.cgi?MASTERCODE=0123456789AB&BRGSSID=myhomelan
设置无线网卡开机画面的路径 http://flashair/config.cgi?MASTERCODE=0123456789AB&CIPATH=/ DCIM/100__TSB/FA000001.jpg
设置主码 http://flashair/config.cgi?MASTERCODE=0123456789AB
上传文件 http://flashair/upload.cgi
删除文件 http://flashair/upload.cgi?DEL=/DCIM/100__TSB/DSC_100.JPG
设置上传目录 http://flashair/upload.cgi?UPDIR=/DCIM/101__TSB
设置系统时间 http://flashair/upload.cgi?FTIME=0x00210000
限制主机设备的写入能力 http://flashair/upload.cgi?WRITEPROTECT=ON
设置连接超时时间 http://flashair/config.cgi?APPAUTOTIME=3000000
应用程序的唯一信息 http://flashair/config.cgi?APPINFO=0123ABCD4567EFGH
无线局域网模式 http://flashair/config.cgi?APPMODE=4
名称 http://flashair/config.cgi?APPNAME=myflashair
网络安全密钥 http://flashair/config.cgi?APPNETWORKKEY=12345678
SSID http://flashair/config.cgi?APPSSID=flashair
网络安全密钥进行互联网直通模式 http://flashair/config.cgi?BRGNETWORKKEY=12345678
SSID的网络直通模式 http://flashair/config.cgi?BRGSSID=myhomelan
卡ID http://flashair/config.cgi?CID=02544d53573038470750002a0200c201
无线开机画面的路径 http://flashair/config.cgi?CIPATH=/ DCIM/100__TSB/FA000001.jpg
默认配置的标志 http://flashair/config.cgi?LOCK=1
主码 http://flashair/config.cgi?MASTERCODE=0123456789AB
产品代码 http://flashair/config.cgi?PRODUCT=FlashAir
上传启用操作标志 http://flashair/config.cgi?UPLOAD=1
供应商代码 http://flashair/config.cgi?VENDOR=TOSHIBA
固件版本 http://flashair/config.cgi?VERSION=F24A6W3AW1.00.03

你可能感兴趣的:(iOS开发 东芝WifiSD卡 读取单反相机照片)