在使用 Apple PTP 时,发现 withCompleteContentCatalog 方法无法触发。解决方法是,需要通过设置 PTPObsterver 对象的 observerValueAvailable 方法来激活这个方法。 具体代码实现如下:
#import "PTPObserver.h"
#import "PTPDeviceManager.h"
@implementation MyPTPObserver
- (void)observerValueAvailable:(PTPValue *)value
{
if ([value isKindOfClass:[PTPListOfObjects class]])
{
PTPListOfObjects *list = (PTPListOfObjects *)value;
NSLog(@"Received content catalog. Count: %lu", (unsigned long)[list.objects count]);
// your code to handle the content catalog
}
}
@end
/**** Rust implementation ****/
pub struct MyPTPObserver {
observer: Arc>,
}
impl ptp_rs::Callbacks for MyPTPObserver {
fn object_added(&self, object_handle: u32) {
// your code to handle new objects
}
fn object_removed(&self, object_handle: u32) {
// your code to handle deleted objects
}
fn object_info_changed(&self, object_handle: u32) {
// your code to handle updated objects
}
fn event_fired(&self, event_code: u16) {
// your code to handle events
}
fn observer_value_available(&self, value: PTPValue) {
if let PTPValue::ListOfObjects(objects) = value {
println!("Received content catalog. Count: {}", objects.len());
// your code to handle the content catalog
}
}
}
fn main() {
let device_list = PTPDeviceManager::new().get_devices().unwrap();
let device = &device_list[0];
let observer = Arc::new(Mutex::new(MyPTPObserver{ observer: observer.clone() }));
let ptp = device.get_ptp_session(observer.clone(), MyPTPDeviceCallbacks{});
// enable the content catalog
ptp.send_operation(
PTPOperation::GetObjectHandles(0, 0, PTPObjectFormat::Undefined, "".to_owned())