在iOS 11 beta 3上初始化MPVolumeView会导致应用程序崩溃。

6
自从iOS 11第三个beta版本以来,我的应用在初始化用于AirPlay的MPVolumeView时开始崩溃。以下代码在早期版本的iOS和iOS 11 beta 1和2上完美运行。
func setupAirplayButton() {
    let rect = CGRect(x: -1000, y: -1000, width: 10, height: 10)
    volumeView = MPVolumeView(frame: rect) //app crashes here
    volumeView.showsVolumeSlider = false
    volumeView.setRouteButtonImage(nil, for: .normal)
    volumeView.translatesAutoresizingMaskIntoConstraints = false
    volumeView.isHidden = true

    if let airplayButton = volumeView.subviews.filter({$0 is UIButton }).first as? UIButton {
        self.airplayButton = airplayButton
        self.airplayButton?.addObserver(self, forKeyPath: "alpha", options: [.initial, .new], context: nil)
    }

    NotificationCenter.default.addObserver(self, selector: #selector(wirelessRouteActiveChanged), name: NSNotification.Name.MPVolumeViewWirelessRouteActiveDidChange, object: nil)

    myView.addSubview(volumeView)
}

是否有其他人遇到相同的问题?

编辑:

崩溃日志

Exception Type:  EXC_CRASH (SIGTRAP)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: MyApp [4543]
Triggered by Thread:  0

Application Specific Information:
BUG IN CLIENT OF LIBDISPATCH: trying to lock recursively

Filtered syslog:
None found
Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x000000018050b4fc (anonymous namespace)::AutoreleasePoolPage::AutoreleasePoolPage(+ 161020 (anonymous namespace)::AutoreleasePoolPage*) + 28
1   libobjc.A.dylib                 0x000000018050b294 (anonymous namespace)::AutoreleasePoolPage::autoreleaseFullPage(objc_object*, + 160404 (anonymous namespace)::AutoreleasePoolPage*) + 60
2   libobjc.A.dylib                 0x000000018050b294 (anonymous namespace)::AutoreleasePoolPage::autoreleaseFullPage(objc_object*, + 160404 (anonymous namespace)::AutoreleasePoolPage*) + 60
3   libobjc.A.dylib                 0x0000000180508e48 objc_object::rootAutorelease2+ 151112 () + 124
4   CoreUI                          0x0000000188a71a48 -[CUICommonAssetStorage renditionInfoForIdentifier:] + 188
5   CoreUI                          0x0000000188a7c408 -[CUIStructuredThemeStore _canGetRenditionWithKey:isFPO:lookForSubstitutions:] + 152
6   CoreUI                          0x0000000188aa5854 -[CUICatalog _resolvedRenditionKeyFromThemeRef:withBaseKey:scaleFactor:deviceIdiom:deviceSubtype:displayGamut:layoutDirection:sizeClassHorizontal:sizeClassVertical:memoryClass:graphicsClass:graphicsFallBackOrder:iconSizeIndex:] + 2112
7   CoreUI                          0x0000000188aa5010 -[CUICatalog _resolvedRenditionKeyForName:scaleFactor:deviceIdiom:deviceSubtype:displayGamut:layoutDirection:sizeClassHorizontal:sizeClassVertical:memoryClass:graphicsClass:graphicsFallBackOrder:withBaseKeySelector:] + 308
8   CoreUI                          0x0000000188aa3d7c -[CUICatalog _namedLookupWithName:scaleFactor:deviceIdiom:deviceSubtype:displayGamut:layoutDirection:sizeClassHorizontal:sizeClassVertical:] + 176
9   CoreUI                          0x0000000188aa406c -[CUICatalog namedLookupWithName:scaleFactor:deviceIdiom:deviceSubtype:displayGamut:layoutDirection:sizeClassHorizontal:sizeClassVertical:] + 156
10  UIKit                           0x000000018b4b4ca0 __139-[_UIAssetManager imageNamed:scale:gamut:layoutDirection:idiom:userInterfaceStyle:subtype:cachingOptions:sizeClassPair:attachCatalogImage:]_block_invoke + 256
11  UIKit                           0x000000018b4b4ae4 -[_UIAssetManager imageNamed:scale:gamut:layoutDirection:idiom:userInterfaceStyle:subtype:cachingOptions:sizeClassPair:attachCatalogImage:] + 224
12  UIKit                           0x000000018b4b5310 -[_UIAssetManager imageNamed:withTrait:] + 576
13  UIKit                           0x000000018acbc6cc +[UIImage imageNamed:inBundle:compatibleWithTraitCollection:] + 220
14  UIKit                           0x000000018aa7cb74 +[UIImage+ 465780 (UIImagePrivate) imageNamed:inBundle:] + 152
15  MediaPlayer                     0x0000000191c36890 -[MPVolumeView _defaultRouteButtonImageAsSelected:] + 120
16  MediaPlayer                     0x0000000191c36704 -[MPVolumeView _createSubviews] + 888
17  MediaPlayer                     0x0000000191c35288 -[MPVolumeView _initWithStyle:] + 204
18  MediaPlayer                     0x0000000191c35370 -[MPVolumeView initWithFrame:style:] + 80
19  MyFramework                     0x0000000101b59a84 @nonobjc MPVolumeView.init() + 645764 (ViewController.swift:0)
20  MyFramework                     0x0000000101b3a83c MPVolumeView.__allocating_init() + 518204 (ViewController.swift:0)
21  MyFramework                     0x0000000101b39b90 ViewController.setupAirplayButton() + 514960 (ViewController.swift:337)
22  MyFramework                     0x0000000101b341a4 ViewController.viewDidAppear(_:) + 491940 (ViewController.swift:132)
23  MyFramework                     0x0000000101b341f4 @objc ViewController.viewDidAppear(_:) + 492020 (ViewController.swift:0)
24  UIKit                           0x000000018aa32e44 -[UIViewController _setViewAppearState:isAnimating:] + 852
25  UIKit                           0x000000018aa9c64c __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke + 44
26  UIKit                           0x000000018aa9c5e8 -[UIViewController _executeAfterAppearanceBlock] + 92
27  UIKit                           0x000000018ac8a368 _runAfterCACommitDeferredBlocks + 556
28  UIKit                           0x000000018ac7d8b4 _cleanUpAfterCAFlushAndRunDeferredBlocks + 288
29  UIKit                           0x000000018ac95614 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 152
30  CoreFoundation                  0x0000000180f85f24 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
31  CoreFoundation                  0x0000000180f85718 __CFRunLoopDoBlocks + 288
32  CoreFoundation                  0x0000000180f83440 __CFRunLoopRun + 852
33  CoreFoundation                  0x0000000180ea5bf0 CFRunLoopRunSpecific + 436
34  GraphicsServices                0x0000000182cfffac GSEventRunModal + 100
35  UIKit                           0x000000018aa7dec4 UIApplicationMain + 208
36  MyApp                           0x000000010164a558 main + 189784 (AppDelegate.swift:14)
37  libdyld.dylib                   0x00000001809ca1e0 start + 4

我也是通过CocoaPods的ImagePicker(https://cocoapods.org/pods/ImagePicker)间接获取到这个。 - MattD
@MattD 你尝试过联系开发人员询问他们是否知道发生了什么吗? - anders
如果您没有初始化框架会发生什么? - solenoid
初始化时没有框架仍然会崩溃。 - anders
3个回答

2

这似乎是模拟器中的问题。在设备上运行不会出现任何问题。


2
这似乎不正确。我在实际设备上运行应用程序时遇到了问题。 - anders
很抱歉听到这个消息。我的iPhone上运行良好(抱歉,不得不说)。无论如何,我正在使用iPhone 7,如果有帮助的话,它运行着iOS 11 beta 3。但是模拟器,最新的Xcode 9,一直崩溃。很抱歉我不能提供更多帮助。 - Dan Morrow
还有一点评论。我尝试像这样实例化它:MPVolumeView() - 没有框架。它仍然在模拟器中崩溃,但我得到了不同的输出:AVOutputContext (FigEndpointPicker) >>>> +[AVFigEndpointPickerOutputContextImpl sharedAudioPresentationOutputContext]: Audio presentation output context not supported by FigEndpointPicker - Dan Morrow
当我尝试在模拟器中实例化MPVolumeView时,我也遇到了同样的问题。因此,我尝试创建一个模拟我的实际项目的示例项目。在那里,我可以很好地创建MPVolumeView,没有崩溃。肯定有什么不可思议的事情发生了。 - anders
我的意思是我能够在实际设备上运行示例而不会崩溃。当然,在模拟器上它仍然会崩溃。 - anders

2

我也遇到了同样的问题。有趣的是:在iPad Pro(12英寸)上可以运行,但在iPhone(7 Plus)上会崩溃。

已尝试使用/不使用框架实例化,按类名,在不同时间通过ObjC进行实例化。

当我多次点击(启动)应用程序时,实际上在某一点上它不会崩溃,但是音量视图实例在视图层次结构中丢失。

我想我们必须等待下一个测试版来解决这个问题。 :-/


是的,我希望这只是一个操作系统或Xcode的问题。到目前为止,我只在iPhone 7上进行了测试,也许我应该尝试在iPad上测试一下。 - anders
由于某种原因,在我的手机上启用飞行模式不会导致应用程序崩溃,但音量视图再次消失了。 - Christian Deckert
好的,所以我最终在iPad(也是12“ Pro)上测试了它,发现与iPhone上的行为相同,即使启用飞行模式也是如此。 - anders

0
iOS 11 beta 4修复了我的应用程序崩溃问题。 但我没有看到UISlider本身。 在此输入图像描述

也为我解决了崩溃问题。 :) - anders

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接