我在应用内购买了swift中的托管内容。没有错误。我的下载队列如下:
func paymentQueue(queue: SKPaymentQueue!, updatedDownloads downloads:[AnyObject]){
for download:AnyObject in downloads {
if let down:SKDownload = download as? SKDownload {
switch down.downloadState {
case .Active:
NSLog("Active %@ %@",down.progress,down.timeRemaining)
break
case .Cancelled:
NSLog("%@","download cancelled")
break
case .Failed:
NSLog("%@","download failed")
productTitle.text = "Download Failed"
break
case .Finished:
NSLog("%@","download finished")
var source = down.contentURL.relativePath
var path = NSBundle.mainBundle().pathForResource("Config", ofType: "plist")
var dict = NSDictionary(contentsOfFile:source.stringByAppendingPathComponent(path))
if !dict.objectForKey("Files"){
SKPaymentQueue.defaultQueue().finishTransaction(down.transaction)
return
}
if let arr = dict["Files"] as? [String] {
for file in arr {
let content:String = source.stringByAppendingPathComponent("Contents").stringByAppendingPathComponent(file)
self.copyPathToDocsFolder(source,target:content)
}
}
SKPaymentQueue.defaultQueue().finishTransaction(down.transaction)
NSLog("Download Complete");
productTitle.text = "Download Complete";
case .Paused:
NSLog("%@","SKDownloadStatePaused")
break
case .Waiting:
NSLog("%@","SKDownloadStateWaiting")
break
default: break
}
}
}
}
这是我永远不会被调用的复制方法。
func copyPathToDocsFolder(source:String,target:String) {
NSLog("Copy function called")
let filemgr:NSFileManager = NSFileManager.defaultManager()
let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let docsDir = dirPaths;
let targetPath = docsDir.stringByAppendingPathComponent(target)
var error:NSError?
if (filemgr.copyItemAtPath(source, toPath:target, error:&error)) {
NSLog("Great Success");
}
else {
NSLog("Error copying file:");
}
}
我正在使用真实的,许可的和配置的设备。当下载委托开始时,Active会在委托的switch语句的第一种情况下跟踪,但下载进度和剩余时间都是nil。有任何想法吗?由于没有错误,我真的不知道如何调试它。
答案 0 :(得分:0)
在案件中。完成陈述
var source = down.contentURL.relativePath
var path = NSBundle.mainBundle().pathForResource("Config", ofType: "plist")
var dict = NSDictionary(contentsOfFile:source.stringByAppendingPathComponent(path))
应该是
var source = down.contentURL.relativePath
var dict = NSMutableDictionary(contentsOfFile: source.stringByAppendingPathComponent("ContentInfo.plist"))
NSBundle.mainBundle()。没有生意在那里。