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

时间:2017-07-14 08:50:56

标签: ios airplay ios11 xcode9-beta mpvolumeview

自iOS 11的第3版开始,我的应用程序在初始化用于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

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:2)

同样在这里。有趣的部分:它正在iPad Pro(12英寸)上工作但在iPhone上崩溃(7加)。

尝试使用/不使用框架名称,通过ObjC在不同时刻进行实例化。

当我多次点击(启动)应用程序时,它实际上不会在某个时刻崩溃,但视图层次结构中缺少卷视图实例。

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

答案 2 :(得分:0)

iOS 11 beta 4修复了我的应用的崩溃问题。 我没有看到UISlider本身。 enter image description here