I'm doing a shop part for iOS application which has two page (first page for show list of voicePack in shop and second page for show detail of voice inside of voicePack).
when click on any cell in the voicePackList go to next page and in next page exists one button with name : DOWNLOAD that I want when I click on that button the voice downloaded and saved in document folder. this is the code that I made inside the button pressed processing:
- (void)downloadingVoice {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Starting Download ...");
NSString *downloadUrl = @"10.3.1.228:9000/files";
NSURL *url = [NSURL URLWithString:downloadUrl];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if (urlData) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *voiceDirectory = [paths objectAtIndex:0];
NSString *voicePaths = [NSString stringWithFormat:@"%@%@", voiceDirectory,@"voice.mp3"];
dispatch_async(dispatch_get_main_queue(), ^{
[urlData writeToFile:voicePaths atomically:YES];
NSLog(@"Saved voice files");
});
}
});
}
- (void)btnDownloadClicked:(id)sender {
NSLog(@"Downloading Voice . . .");
[self downloadingVoice];
}
and here are how I put the button below the list of voices:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 60.0f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
// if(tableView == self.shopTableView) {
UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 40)];
UIButton *download = [UIButton buttonWithType:UIButtonTypeCustom];
[download setTitle:@"Download" forState:UIControlStateNormal];
[download addTarget:self action:@selector(btnDownloadClicked:) forControlEvents:UIControlEventTouchUpInside];
[download setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
download.frame = CGRectMake(0, 0, 130, 30);
[footerView addSubview:download];
return footerView;
}
when I click the button and put some breakpoints, it's end after if (urlData)
when I check the urlData and downloadUrl, it says:
2015-09-17 10:53:01.926 Selfie[87197:674517] Starting Download ...
(lldb) po urlData
error: Couldn't materialize: couldn't get the value of variable urlData: no location, value may have been optimized out
Errored out in Execute, couldn't PrepareToExecuteJITExpression
(lldb) po downloadUrl
error: Couldn't materialize: couldn't get the value of variable downloadUrl: variable not available
Errored out in Execute, couldn't PrepareToExecuteJITExpression
anyone please help me to solve this.. I'll be really thank you for your help..