MPVolumeView initialization causes application crash on iOS 11 beta 3

With the third beta of iOS 11, my app started crashing when initializing the MPVolumeView used for AirPlay. The following code snippet works fine in earlier versions of iOS and iOS 11 beta 1 and 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)
}

Does anyone have another problem?

Edit:

Crash log

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
+6
source share
3 answers

iOS 11 beta 4 fixed crash issues for my application. However, I do not see the UISlider itself. enter image description here

0
source

This seems like a problem in the simulator. Starting the device does not cause problems.

+2
source

. : iPad Pro (12 "), iPhone (7 ).

/ , , ObjC .

When I continue to click (run) the application several times, it actually will not crash at some point, but the instance of the volume view is missing from the view hierarchy.

I think we will have to wait for the next beta to fix this problem .: - /

+2
source

All Articles