首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@escaping @callee_guaranteed (@unowned )的崩溃

@escaping @callee_guaranteed (@unowned )的崩溃
EN

Stack Overflow用户
提问于 2020-06-15 13:36:24
回答 1查看 1.4K关注 0票数 1

我的用户正面临着在Firebase Crashlytics中报告的这个崩溃。我可以看到发生崩溃的类和方法,但找不出崩溃的原因。在模拟器和我拥有的真实设备上,一切都工作得很好。

我需要一些帮助来找出坠机的真正原因。这是崩溃日志。

代码语言:javascript
复制
Crashed: com.apple.main-thread
0  OK Tested                      0x1049dc4a0 closure #1 in VideoPlayerController.setProgressLabel() + 336 (VideoPlayerController.swift:336)
1  OK Tested                      0x1049da494 thunk for @escaping @callee_guaranteed (@unowned CMTime) -> () + 4308100244 (<compiler-generated>:4308100244)
2  AVFoundation                   0x1abaefd9c -[AVPeriodicTimebaseObserver _fireBlockForTime:] + 60
3  AVFoundation                   0x1abaf03a4 -[AVPeriodicTimebaseObserver _handleTimeDiscontinuity] + 164
4  AVFoundation                   0x1abaf125c __AVTimebaseObserver_timebaseNotificationCallback_block_invoke + 112
5  libdispatch.dylib              0x1a158e9a8 _dispatch_call_block_and_release + 24
6  libdispatch.dylib              0x1a158f524 _dispatch_client_callout + 16
7  libdispatch.dylib              0x1a15726fc _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 860
8  CoreFoundation                 0x1a1847748 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
9  CoreFoundation                 0x1a184261c __CFRunLoopRun + 1724
10 CoreFoundation                 0x1a1841c34 CFRunLoopRunSpecific + 424
11 GraphicsServices               0x1ab98b38c GSEventRunModal + 160
12 UIKitCore                      0x1a597422c UIApplicationMain + 1932
13 OK Tested                      0x104901480 main + 21 (GoogleAds.swift:21)
14 libdyld.dylib                  0x1a16c9800 start + 4

和实际的代码。这部分代码用于设置进度滑块和标签,以指示AVPlayerItem的进度

代码语言:javascript
复制
private func setProgressLabel() {

        player.addPeriodicTimeObserver(forInterval: CMTimeMakeWithSeconds(1/30.0, preferredTimescale: Int32(NSEC_PER_SEC)), queue: DispatchQueue.main) { [unowned self] time in

//            guard let self = self else { return }

            if let playerItem = self.player.currentItem {

                let totalDuration : CMTime = playerItem.asset.duration
                let totalDurationInSeconds : Float64 = CMTimeGetSeconds(totalDuration)

                let totalDurationInString = Functions.stringFromTimeInterval(interval: totalDurationInSeconds)

                let duration : CMTime = playerItem.currentTime()
                let seconds : Float64 = CMTimeGetSeconds(duration)

                let currentDurationInString = Functions.stringFromTimeInterval(interval: seconds)

                self.progressLabel.text = "\(currentDurationInString)/\(totalDurationInString)"

                self.progressSlider.maximumValue = Float(totalDurationInSeconds)
                self.progressSlider.setValue(Float(seconds), animated: true)

                // For Analytics: video tracking
                let percentageComplete = Float(seconds / totalDurationInSeconds * 100)

                if percentageComplete.isNaN {
                    return
                }

                if Int(seconds) == 5 || Int(seconds) == 10 {
                    if Int(seconds) != self.eventSentForQuartile {
                        self.quartile = Int(seconds)
                        self.eventSentForQuartile = self.quartile
                        // send event for quartile
                        print("Send event for quartile \(self.quartile) at time \(Int(seconds))")
                        self.trackVideoOnPlay(firstPlay: false, watchDuration: "\(Int(seconds))")
                    }
                }

                if Int(seconds) == 30 && !self.isCustomEventFor30SecondsSent {
                    AppAnalytics.playVideoEvent(video: self.video)
                    self.isCustomEventFor30SecondsSent = true
                }

                if Int(percentageComplete) == 25 || Int(percentageComplete) == 50 || Int(percentageComplete) == 75 || Int(percentageComplete) == 95 {
                    if Int(percentageComplete) != self.eventSentForQuartile {
                        self.quartile = Int(percentageComplete)
                        self.eventSentForQuartile = self.quartile
                        // send event for quartile
                        print("Send event for quartile \(self.quartile) at time \(Int(seconds))")
                        self.trackVideoOnPlay(firstPlay: false, watchDuration: "\(Int(seconds))")
                    }
                }
            }
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2020-09-17 06:31:41

不要使用非自己的自我。因为self可以为零。遵循以下代码:

代码语言:javascript
复制
private func setProgressLabel() {

        player.addPeriodicTimeObserver(forInterval: CMTimeMakeWithSeconds(1/30.0, preferredTimescale: Int32(NSEC_PER_SEC)), queue: DispatchQueue.main) { [weak self] time in

guard let self = self else { return }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62381938

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档