6

Since 3rd beta of iOS 11 my app has started crashing when initialising a MPVolumeView used for AirPlay. The following piece of code is working perfectly fine on 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)
}

Is anyone else experiencing the same issue?

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
anders
  • 457
  • 2
  • 19

3 Answers3

2

This appears to be a problem in the simulator. Running on the device causes no issues.

Dan Morrow
  • 4,433
  • 2
  • 31
  • 45
  • 2
    This does not seem to be correct. I am seeing the issue running the app on an actual device. – anders Jul 19 '17 at 06:25
  • sorry to hear. Works fine on my iPhone (sorry, had to say it). Anyway, I'm running an iPhone 7, if that helps, with iOS 11, beta 3. But the simulator, latest Xcode 9, crashes consistently. Sorry I couldn't be more help. – Dan Morrow Jul 19 '17 at 14:40
  • One more comment. I tried instantiating it like this: `MPVolumeView()` - without a frame. It still crashed in the sim, but I got different output: `AVOutputContext (FigEndpointPicker) >>>> +[AVFigEndpointPickerOutputContextImpl sharedAudioPresentationOutputContext]: Audio presentation output context not supported by FigEndpointPicker` – Dan Morrow Jul 19 '17 at 14:51
  • Same thing happens to me when I try to instantiate a `MPVolumeView` while using the simulator. So I just tried creating a sample project which simulates my actual project. In that I am able to create the MPVolumeView just fine. No crash. Something is definitely spooky. – anders Jul 20 '17 at 10:50
  • And by that I mean that I am able to run the sample on an actual device without it crashing. On the simulator it still crashes of course. – anders Jul 20 '17 at 12:18
2

Same here. The funny part: it‘s working on the iPad Pro (12“) but crashing on the iPhone (7 plus).

Tried instantiating with/without frame, by class name, via ObjC at different moments.

When I keep tapping (starting) the app multiple times it actually won’t crash at some point, but the volume view instance is missing in the view hierarchy.

I guess we have to wait for the next beta to fix this issue. :-/

  • Yeah, I'm hoping that this turns out being an OS or Xcode issue. So far I have only tested on an iPhone 7, maybe I should try taking an iPad for a spin as well. – anders Jul 21 '17 at 08:30
  • For some reason starting the app with airplane mode enabled won’t cause a crash on my phone but volume view is missing again. – Christian Deckert Jul 21 '17 at 16:04
  • Alright, so I finally got to test it on an iPad (also the 12" Pro), and I see the same behaviour as on the iPhone. Even when airplane mode is enabled. – anders Jul 24 '17 at 07:42
0

iOS 11 beta 4 fixed the crash issues for my app. I don‘t see the UISlider itself though. enter image description here