Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot instantiate AVPlayerViewController error

Experimenting with creating a simple app to play video on the iPhone (Xcode 7.3, swift iOS9) and I'm just trying to get the player to appear before adding code to load content.

Using storyboard, created a button and segue (show) to an AVViewController object. When app is run on device and button is pressed, I get:

"Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named AVPlayerViewController' "

Prior to declaring my ViewContrller: UIViewController class I have: import UIKit, import AVKit and import AVFoundation. What's missing? I suspect something else I need to import but my research has only turned up AVKit and AVFoundation as necessary.

like image 964
EdDry Avatar asked Jul 20 '26 02:07

EdDry


1 Answers

I found a solution while viewing answers to other similar problems here on Stack Overflow.

To allow the app to run correctly I had to manually link the frameworks to my project.

In Xcode I clicked on my project's name to get to settings, then added AVFoundation.framework and AVKit.framework in the Linked Frameworks and Libraries section. Now running the app allowed me to instantiate a AVPlayerViewController object without any problems. Apparently, importing AVKit and AVFoundation in my code was not enough. Anyone know why I had to explicitly link the frameworks?

like image 73
EdDry Avatar answered Jul 21 '26 21:07

EdDry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!