/// <summary> /// New iOS6 method to save downloads of hosted-content /// </summary> public void SaveDownload(SKDownload download) { Console.WriteLine("SaveDownload " + download.ContentIdentifier); Console.WriteLine(" from " + download.ContentUrl.Path); var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Documents folder var targetfolder = System.IO.Path.Combine(documentsPath, download.Transaction.Payment.ProductIdentifier); Console.WriteLine(" to " + targetfolder); if (!System.IO.Directory.Exists(targetfolder)) { System.IO.Directory.CreateDirectory(targetfolder); } foreach (var file in System.IO.Directory.EnumerateFiles (System.IO.Path.Combine(download.ContentUrl.Path, "Contents"))) { Console.WriteLine(" file to copy " + file); var fileName = file.Substring(file.LastIndexOf("/") + 1); var newFilePath = System.IO.Path.Combine(targetfolder, fileName); if (!System.IO.File.Exists(newFilePath)) { System.IO.File.Copy(file, newFilePath); } else { Console.WriteLine("already exists " + newFilePath); } } CompleteTransaction(download.Transaction); // so it gets 'finished' }
/// <Docs> /// New iOS 6 method to track downloads of hosted-content /// </Docs> public override void UpdatedDownloads (SKPaymentQueue queue, SKDownload[] downloads) { Console.WriteLine (" -- PaymentQueueUpdatedDownloads"); foreach (SKDownload download in downloads) { switch (download.DownloadState) { case SKDownloadState.Active: Console.WriteLine ("Download progress:" + download.Progress); Console.WriteLine ("Time remaining: " + download.TimeRemaining); break; case SKDownloadState.Finished: Console.WriteLine ("Finished!!!!"); Console.WriteLine ("Content URL:" + download.ContentUrl); // UNPACK HERE! theManager.SaveDownload (download); break; case SKDownloadState.Failed: Console.WriteLine ("Failed"); break; case SKDownloadState.Cancelled: Console.WriteLine ("Cancelled"); break; case SKDownloadState.Paused: case SKDownloadState.Waiting: break; default: break; } } }
/// <summary> /// New iOS6 method to save downloads of hosted-content /// </summary> public void SaveDownload (SKDownload download) { Console.WriteLine ("SaveDownload " + download.ContentIdentifier); Console.WriteLine (" from " + download.ContentUrl.Path); var documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder var targetfolder = System.IO.Path.Combine (documentsPath, download.Transaction.Payment.ProductIdentifier); Console.WriteLine (" to " + targetfolder); if (!System.IO.Directory.Exists (targetfolder)) System.IO.Directory.CreateDirectory (targetfolder); foreach (var file in System.IO.Directory.EnumerateFiles (System.IO.Path.Combine(download.ContentUrl.Path,"Contents"))) { Console.WriteLine (" file to copy " + file); var fileName = file.Substring (file.LastIndexOf ("/") + 1); var newFilePath = System.IO.Path.Combine(targetfolder, fileName); if (!System.IO.File.Exists(newFilePath)) System.IO.File.Copy (file, newFilePath); else Console.WriteLine ("already exists " + newFilePath); } CompleteTransaction (download.Transaction); // so it gets 'finished' }