ios - WatchKit WKInterfaceMovie fatal error : unexpectedly found nil while unwrapping an Optional value

标签 ios xcode swift watchkit

import WatchKit
import Foundation


class InterfaceController: WKInterfaceController {

let video = NSBundle.mainBundle().URLForResource("video", withExtension: "mp4")

@IBOutlet var videoShown: WKInterfaceMovie!

override func awakeWithContext(context: AnyObject?) {
    super.awakeWithContext(context)

    // Configure interface objects here.
    videoShown.setMovieURL(video!)
}

override func willActivate() {
    // This method is called when watch view controller is about to be visible to user
    super.willActivate()
}

override func didDeactivate() {
    // This method is called when watch view controller is no longer visible
    super.didDeactivate()
}

}

我的代码如上所示,我尝试使用 WKInterfaceMovie 在 WatchKit 应用程序上播放位于 XCode 资源文件夹中的视频,但在应用程序加载时出现此错误:

fatal error: unexpectedly found nil while unwrapping an Optional value

最佳答案

问题可能出在您的视频位置。将文件复制到“WatchKit Extension”文件夹中,而不是复制到 Assets 文件夹中。

关于ios - WatchKit WKInterfaceMovie fatal error : unexpectedly found nil while unwrapping an Optional value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33972393/

相关文章:

ios - 在 Facebook 上分享最佳成绩

iOS - UITableViewCell 更改高度取决于数据单元格保留

iphone - iOS : Call a method just one time

ios - 当用户位于特定位置时如何获取基于位置的内容?

ios - 以编程方式/代码将过渡设置为部分 curl

ios - Action Sheet 在 iphone 中有效,但在 ipad 中无效

xcode - iOS:表格 View 中的搜索栏

ios - 为什么 Xcode 在从逻辑单元测试目标执行测试时启动模拟器?

ios - RxSwift - UIImageView - 观察属性 isHighlighted

arrays - 如何从数组中打乱文本而不重复单词并遍历整个数组? ( swift )