0

一直在努力将 IAP 下载(包含几个 mp4 视频文件)从缓存移动到文件管理器位置并使用这些文件。我在 SKDownload .finished: 中使用此代码来移动文件

   guard let path2 = download.contentURL?.appendingPathComponent("Contents") else {
                    return
                }
                    let path = path2.absoluteString
                    
                    queue.finishTransaction(download.transaction)
                
                let fileManager = FileManager.default
                var files: NSArray!
                do {
                    files = try fileManager.contentsOfDirectory(atPath: path) as NSArray
                } catch let err as NSError {
                    print("Error finding zip URL", err.localizedDescription)
                }

                for file in files {
    
                    var pathDestination: NSString = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0] as NSString
                    pathDestination = pathDestination.appendingPathComponent(file as! String) as NSString
                    
                    userDefaults.set(pathDestination, forKey: "source")
                    
                    do {
                        try fileManager.moveItem(atPath: path, toPath: pathDestination as String)
                        print("File", file, "Moved")
                    }catch let err as NSError {
                        print("Couldn't move file", err.localizedDescription)
                    }
                }   
                }

然后我放入播放视频文件的VC(currentVideo var是视频文件的名称)


let source = userDefaults.string(forKey: "source")!
            let path2 = source + currentVideo + ".mp4"
            player = AVPlayer(url: NSURL(fileURLWithPath: path2) as URL)
            self.playerLayer = AVPlayerLayer(player: player)
            playerLayer.frame = self.gameview.frame
            playerLayer.videoGravity = AVLayerVideoGravity.resizeAspect
            playerLayer.zPosition = -1
            self.gameview.layer.addSublayer(playerLayer)
            self.player.volume = 0.5
            self.player.play()

我哪里错了?另外我会把 queue.finishTransaction(transaction) 放在哪里?完成下载后显然需要采取行动,但如果我将其插入 SKDownload .finished 中,则它超出了 SKpaymentQueue 的范围,因此无法识别“交易”。我假设 queue.finishTransaction(download.transaction) 只完成了下载交易,没有完成支付交易?或者是吗?如果您还可以编辑代码,使其从用户备份中排除下载的文件,您将获得奖励积分:-)

4

0 回答 0