Connect the SONY camera to the iPhone through the data cable, and get pictures taken by the SONY camera on the phone in real time

  Kiến thức lập trình

I need to develop a function for real-time access to pictures taken by SONY camera on iOS. It links iPhone with SONY camera through data cable, and then SONY camera takes pictures and real-time access to pictures taken by camera on iPhone. But at the moment I don’t know how to implement this feature.

- (void)sonyAddTimer {
    self.timer = [NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:@selector(getEventData3) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}

- (void)getEventData3 {
    //获取事件数据
    NSData*               commandBuffer = NULL;
    PTPOperationRequest*  request       = [[PTPOperationRequest alloc] init];
    request.operationCode       = PTPOperationCodeGetEventData3;
    request.numberOfParameters  = 0;
    commandBuffer               = request.commandBuffer;
    
    NSLog(@"nSending PTP request:%@",[request description]);
    
    if (@available(iOS 13.0, *)) {
        [self.cameraDevice requestSendPTPCommand:commandBuffer outData:NULL completion:^(NSData * _Nonnull responseData, NSData * _Nonnull ptpResponseData, NSError * _Nullable error) {
            NSLog(@"getEventData3---responseData = %@", responseData);
            PTPOperationResponse *ptpResponse = NULL;
            if ( ptpResponseData ) {
                ptpResponse = [[PTPOperationResponse alloc] initWithData:ptpResponseData];
                NSLog(@"n getEventData3 Received response:%@",[ptpResponse description]);

                [self getObjectInfoWithInt:0xffffc001];
                
            }
        }];
    } else {
        
    }
}

- (void)getObjectInfoWithInt:(int)intValue2 {
    //获取对象信息
    NSData*               commandBuffer = NULL;
    PTPOperationRequest*  request       = [[PTPOperationRequest alloc] init];
    
    request.operationCode       = PTPOperationCodeGetObjectInfo;
    request.numberOfParameters  = 1;
    request.parameter1          = intValue2;
    commandBuffer               = request.commandBuffer;
    
    NSLog(@"nSending PTP request:%@",[request description]);
    
    if (@available(iOS 13.0, *)) {
        [self.cameraDevice requestSendPTPCommand:commandBuffer outData:NULL completion:^(NSData * _Nonnull responseData, NSData * _Nonnull ptpResponseData, NSError * _Nullable error) {
            PTPOperationResponse *ptpResponse = NULL;
            if ( ptpResponseData ) {
                ptpResponse = [[PTPOperationResponse alloc] initWithData:ptpResponseData];
                NSLog(@"n getObjectInfo Received response:%@",[ptpResponse description]);
                
                NSLog(@"getObjectInfo--responseData=%@",responseData);
                
                [self getObjectWithIntValue:intValue2];
            }
        }];
    } else {
        // Fallback on earlier versions
    }
}

- (void)getObjectWithIntValue:(int)intValue2 {
    //获取对象
    NSData*               commandBuffer = NULL;
    PTPOperationRequest*  request       = [[PTPOperationRequest alloc] init];
    
    request.operationCode       = PTPOperationCodeGetObject;
    request.numberOfParameters  = 1;
    request.parameter1          = intValue2;
    commandBuffer               = request.commandBuffer;
    
    NSLog(@"nSending PTP request:%@",[request description]);
    
    if (@available(iOS 13.0, *)) {
        [self.cameraDevice requestSendPTPCommand:commandBuffer outData:NULL completion:^(NSData * _Nonnull responseData, NSData * _Nonnull ptpResponseData, NSError * _Nullable error) {
            PTPOperationResponse *ptpResponse = NULL;
            if ( ptpResponseData ) {
                ptpResponse = [[PTPOperationResponse alloc] initWithData:ptpResponseData];
                NSLog(@"n getObject Received response:%@",[ptpResponse description]);
                
                NSLog(@"getObject---responseData=%@",responseData);
                
                UIImage *image = [UIImage imageWithData:responseData];
                
                if (image) {
                    NSString *imgMd5String = [self calculateMD5ForJPEGImage:image];
                    NSLog(@"图片MD5值 imgMd5String = %@",imgMd5String);
                    
                    [self uploadImageWithImage:image md5String:imgMd5String];
                    
                }
                
                
            }
        }];
    } else {
        
    }
}

This is the code I tried to write, but with the frequent disconnection and re-link of the camera, I have confirmed that the data cable and the camera plug are in good condition.

LEAVE A COMMENT