У меня возникла проблема с отправкой файлов в Apple Watch с родительского устройства. Иногда файл проходит и полностью разбирается. В других случаях начинается передача файла, но он терпит неудачу и даже не очищает метод session:(WCSession *)session didReceiveFile:(WCSessionFile *)file
от Apple Watch.Ошибка передачи файла WCSession
Вот родительский код устройства:
- (void)sendLiveAudioRecording
{
NSError *moveError;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *groupURL = [fileManager containerURLForSecurityApplicationGroupIdentifier: @"group.myCompany.myApp"];
NSURL *permanentURL = [groupURL URLByAppendingPathComponent: @"PhoneToWatch.mp4"];
[FileSystem_Helper removeFile: [permanentURL path]];
[fileManager moveItemAtURL: [self fileURL] toURL: permanentURL error: &moveError];
if (!moveError)
{
if ([WCSession isSupported])
{
[[WCSession defaultSession] setDelegate: self];
[[WCSession defaultSession] activateSession];
if ([[WCSession defaultSession] isReachable])
{
NSLog(@"File Is Being Transferred: %@", [permanentURL path]);
[[WCSession defaultSession] transferFile: permanentURL metadata: nil];
}
else
{
[self createAlertWithTitle: @"Error" andMessage: @"WCSession Not Reachable"];
}
}
else
{
[self createAlertWithTitle: @"Error" andMessage: @"WCSession Not Supported"];
}
}
else
{
NSLog(@"%@", [moveError localizedDescription]);
}
}
А вот код компании Apple Watch:
-(void) session:(WCSession *)session didReceiveFile:(WCSessionFile *)file
{
NSData *fileData = [NSData dataWithContentsOfURL: [file fileURL]];
WKAudioFileAsset *asset = [WKAudioFileAsset assetWithURL: [file fileURL]];
NSURL *fileLocation = [FileSystem_Helper writeAudioToAppGroupsWithData: fileData withName: @"FromPhone.mp4"];
NSLog(@"%@", [file fileURL]);
NSLog(@"%@", [fileLocation path]);
[FileSystem_Helper removeFile: [[file fileURL] path]];
NSError *writingError;
if (!writingError)
{
[self playURL: fileLocation withDuration: [asset duration]];
}
else
{
[WKAlertViewController_Helper showWKAlertControllerWithTitle: @"Audio Receive Failed" andMessage: [writingError localizedDescription] andButtonTitle: @"Ok" onController: self];
}
}
Я даже не уверен, что это не имеет ничего общего с самим кодом. Я думаю, что передача файлов иногда не срабатывает, но я не могу найти нигде, чтобы распечатать ошибку для отладки.
Может ли кто-нибудь дать мне некоторое представление здесь?
IOS 9,2 & & WatchOS 2,1
Вот код из [FileSystem_Helper removeFile: (NSString *) Filepath]:
+ (void) removeFile: (NSString *)filePath
{
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath: filePath])
{
NSError *error;
if (![fileManager removeItemAtPath: filePath error:&error])
{
NSLog(@"Error removing file: %@", error);
}
}
}
А вот [FileSystem_Helper writeAudioToAppGroupsWithData]:
+ (void)writeAudioToAppGroupsWithData: (NSData *)audioData withName: (NSString *)name
{
// Writing the audio data to the App Groups
NSURL *URL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier: @"group.myCompany.myApp"];
NSURL *containerURL = [URL URLByAppendingPathComponent: name];
[audioData writeToURL: containerURL atomically: YES];
}
Выполняется ли обратный вызов делегата didTransferFile на стороне отправки при неудачной передаче? Если да, то какая-нибудь ошибка? – ccjensen
@ccjensen Делегат didTransferFile вызывается каждый раз, когда погода получена на стороне часового или нет. Я даже, возможно, пытаюсь выполнить оператор if в файле didTransferFile следующим образом: if ([fileTransfer] file]) {NSLog (@ "SUCCESS"); else {NSLog (@ "FAILED")}, но там не повезло. –
Я готов написать свой ответ, но хотел проверить, что делает '[FileSystem_Helper removeFile:]' делает? Не могли бы вы разместить свой код? – ccjensen