-2
如何檢查文件是否下載並保存在設備上?請幫幫我。如何檢查文件是否下載?
- (void) song{
if (_index1 == 0) {
NSString *stringURL = @"https://drive.google.com/uc?export=download&id=0B0EJbcHq3ZALWUo0a05LMWNzeDg";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if (urlData)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"music.mp3"];
[urlData writeToFile:filePath atomically:YES];
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:filePath] error:nil];
}
}
}
您是否檢查了[Google雲端硬盤iOS版API指南](https://developers.google.com/驅動/ IOS/devguide /文件)? –
[如何在iOS上使用目標C在本地下載和保存文件?](http://stackoverflow.com/questions/5323427/how-do-i-download-and-save-a-file- local-on-ios-using-objective-c) – Abhijeet
每次按下播放按鈕時都會下載文件。我需要檢查文件是否已經下載。 –