IOS In App Purchase永远不会离开激活状态



我有一个在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
            }
        }
    }
}

这里是永远不会被调用的copy方法

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。什么好主意吗?我真的不知道如何调试这个,因为没有错误。

在case .Finished语句

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()。

最新更新