我的团队有一个应用程序,该应用程序在Mac上使用MobileDevice.framework和iDeviceFramework.framework将文件复制到iOS设备上。
在iOS 13 Beta中,尝试向设备读取或写入文件时我们超时。 可以获取设备的详细信息,但是当我们尝试访问特定应用的沙箱时,对其进行读/写操作会超时
AFCFileLine="411" AFCCode="-402636788"
NSDebugDescription="Operation timed out"
AFCFileName="platform.c" AFCVersion="270"
NSUnderlyingError="60" NSDecription="keventtimeout"
使用AFCFileRefOpen函数时发生超时错误。当使用MobileDevice头文件中的所有类似功能时(例如, AFCFileRefRead,AFCFileRefWrite等。
我们尝试测试一些商用工具(例如iExplorer),并发现它们在与iOS 13设备一起使用时在控制台日志中显示相同的错误。
我们使用以下代码作为示例对其进行测试:
static void upload(AMDeviceRef device) {
service_conn_t houseFd = start_house_arrest_service(device);
struct afc_connection afc_conn;
struct afc_connection* afc_conn_p = &afc_conn;
AFCConnectionOpen(houseFd, 0, &afc_conn_p);
NSString *destination = [NSString pathWithComponents:@[@"/Documents/",
copy_dest]];
upload_file(afc_conn_p, [copy_source UTF8String], [destination UTF8String]);
assert(AFCConnectionClose(afc_conn_p) == 0);
}
// Used to send files to app-specific sandbox (Documents dir)
service_conn_t start_house_arrest_service(AMDeviceRef device) {
AMDeviceConnect(device);
assert(AMDeviceIsPaired(device));
assert(AMDeviceValidatePairing(device) == 0);
assert(AMDeviceStartSession(device) == 0);
service_conn_t houseFd;
if (AMDeviceStartHouseArrestService(device, (__bridge CFStringRef)bundle_id,
0, &houseFd, 0) != 0)
{
Log(@"Unable to find bundle with id: %@\n", bundle_id);
exit(EXIT_FAILURE);
}
assert(AMDeviceStopSession(device) == 0);
assert(AMDeviceDisconnect(device) == 0);
return houseFd;
}
static bool upload_file(struct afc_connection* afc_conn_p,
const char* source_name, const char* dest_name)
{
// open source
FILE* pSource = fopen(source_name, "r");
if (!pSource) {
return false;
}
// open destination
afc_file_ref file_ref;
// ******** TIMEOUT SEEN HERE IN AFCFileRefOpen
afc_error_t err = AFCFileRefOpen(afc_conn_p, dest_name, 2, &file_ref);
// ******** TIMEOUT SEEN HERE IN AFCFileRefOpen
if (err) {
fclose(pSource);
return false;
}
size_t bufferSize = 4096;
uint8_t buffer[bufferSize];
while (!feof(pSource)) {
size_t n = fread(buffer, 1, bufferSize, pSource);
err = AFCFileRefWrite(afc_conn_p, file_ref, buffer, (unsigned int)n);
if (err) {
fclose(pSource);
AFCFileRefClose(afc_conn_p, file_ref);
return false;
}
}
fclose(pSource);
AFCFileRefClose(afc_conn_p, file_ref);
return true;
}