fix(ios): Add safety checks and remove some of the ! in types declaration (#4182)
This commit is contained in:
parent
17dc2c064f
commit
ae82c83eef
@ -81,22 +81,25 @@ enum RCTVideoUtils {
|
||||
return 0
|
||||
}
|
||||
|
||||
static func urlFilePath(filepath: NSString!, searchPath: FileManager.SearchPathDirectory) -> NSURL! {
|
||||
if filepath.contains("file://") {
|
||||
return NSURL(string: filepath as String)
|
||||
static func urlFilePath(filepath: NSString?, searchPath: FileManager.SearchPathDirectory) -> NSURL! {
|
||||
guard let _filepath = filepath else { return nil }
|
||||
|
||||
if _filepath.contains("file://") {
|
||||
return NSURL(string: _filepath as String)
|
||||
}
|
||||
|
||||
// if no file found, check if the file exists in the Document directory
|
||||
let paths: [String]! = NSSearchPathForDirectoriesInDomains(searchPath, .userDomainMask, true)
|
||||
var relativeFilePath: String! = filepath.lastPathComponent
|
||||
let paths: [String] = NSSearchPathForDirectoriesInDomains(searchPath, .userDomainMask, true)
|
||||
var relativeFilePath: String = _filepath.lastPathComponent
|
||||
// the file may be multiple levels below the documents directory
|
||||
let directoryString: String! = searchPath == .cachesDirectory ? "Library/Caches/" : "Documents"
|
||||
let fileComponents: [String]! = filepath.components(separatedBy: directoryString)
|
||||
let directoryString: String = searchPath == .cachesDirectory ? "Library/Caches/" : "Documents"
|
||||
let fileComponents: [String] = _filepath.components(separatedBy: directoryString)
|
||||
if fileComponents.count > 1 {
|
||||
relativeFilePath = fileComponents[1]
|
||||
}
|
||||
|
||||
let path: String! = (paths.first! as NSString).appendingPathComponent(relativeFilePath)
|
||||
guard let _pathFirst = paths.first else { return nil }
|
||||
let path: String = (_pathFirst as NSString).appendingPathComponent(relativeFilePath)
|
||||
if FileManager.default.fileExists(atPath: path) {
|
||||
return NSURL.fileURL(withPath: path) as NSURL
|
||||
}
|
||||
@ -135,7 +138,7 @@ enum RCTVideoUtils {
|
||||
return []
|
||||
}
|
||||
|
||||
let audioTracks: NSMutableArray! = NSMutableArray()
|
||||
let audioTracks = NSMutableArray()
|
||||
|
||||
let group = await RCTVideoAssetsUtils.getMediaSelectionGroup(asset: asset, for: .audible)
|
||||
|
||||
@ -146,14 +149,14 @@ enum RCTVideoUtils {
|
||||
if (values?.count ?? 0) > 0, let value = values?[0] {
|
||||
title = value as! String
|
||||
}
|
||||
let language: String! = currentOption?.extendedLanguageTag ?? ""
|
||||
let language: String = currentOption?.extendedLanguageTag ?? ""
|
||||
|
||||
let selectedOption: AVMediaSelectionOption? = player.currentItem?.currentMediaSelection.selectedMediaOption(in: group!)
|
||||
|
||||
let audioTrack = [
|
||||
"index": NSNumber(value: i),
|
||||
"title": title,
|
||||
"language": language ?? "",
|
||||
"language": language,
|
||||
"selected": currentOption?.displayName == selectedOption?.displayName,
|
||||
] as [String: Any]
|
||||
audioTracks.add(audioTrack)
|
||||
@ -178,7 +181,7 @@ enum RCTVideoUtils {
|
||||
if (values?.count ?? 0) > 0, let value = values?[0] {
|
||||
title = value as! String
|
||||
}
|
||||
let language: String! = currentOption?.extendedLanguageTag ?? ""
|
||||
let language: String = currentOption?.extendedLanguageTag ?? ""
|
||||
let selectedOption: AVMediaSelectionOption? = player.currentItem?.currentMediaSelection.selectedMediaOption(in: group!)
|
||||
let textTrack = TextTrack([
|
||||
"index": NSNumber(value: i),
|
||||
@ -363,10 +366,11 @@ enum RCTVideoUtils {
|
||||
static func prepareAsset(source: VideoSource) -> (asset: AVURLAsset?, assetOptions: NSMutableDictionary?)? {
|
||||
guard let sourceUri = source.uri, sourceUri != "" else { return nil }
|
||||
var asset: AVURLAsset!
|
||||
let bundlePath = Bundle.main.path(forResource: source.uri, ofType: source.type) ?? ""
|
||||
let url = source.isNetwork || source.isAsset
|
||||
? URL(string: source.uri ?? "")
|
||||
: URL(fileURLWithPath: bundlePath)
|
||||
let bundlePath = Bundle.main.path(forResource: sourceUri, ofType: source.type) ?? ""
|
||||
guard let url = source.isNetwork || source.isAsset
|
||||
? URL(string: sourceUri)
|
||||
: URL(fileURLWithPath: bundlePath) else { return nil }
|
||||
|
||||
let assetOptions: NSMutableDictionary! = NSMutableDictionary()
|
||||
|
||||
if source.isNetwork {
|
||||
@ -375,9 +379,9 @@ enum RCTVideoUtils {
|
||||
}
|
||||
let cookies: [AnyObject]! = HTTPCookieStorage.shared.cookies
|
||||
assetOptions.setObject(cookies as Any, forKey: AVURLAssetHTTPCookiesKey as NSCopying)
|
||||
asset = AVURLAsset(url: url!, options: assetOptions as? [String: Any])
|
||||
asset = AVURLAsset(url: url, options: assetOptions as? [String: Any])
|
||||
} else {
|
||||
asset = AVURLAsset(url: url!)
|
||||
asset = AVURLAsset(url: url)
|
||||
}
|
||||
return (asset, assetOptions)
|
||||
}
|
||||
|
@ -48,12 +48,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
private var _preventsDisplaySleepDuringVideoPlayback = true
|
||||
private var _preferredForwardBufferDuration: Float = 0.0
|
||||
private var _playWhenInactive = false
|
||||
private var _ignoreSilentSwitch: String! = "inherit" // inherit, ignore, obey
|
||||
private var _mixWithOthers: String! = "inherit" // inherit, mix, duck
|
||||
private var _resizeMode: String! = "cover"
|
||||
private var _ignoreSilentSwitch: String = "inherit" // inherit, ignore, obey
|
||||
private var _mixWithOthers: String = "inherit" // inherit, mix, duck
|
||||
private var _resizeMode: String = "cover"
|
||||
private var _fullscreen = false
|
||||
private var _fullscreenAutorotate = true
|
||||
private var _fullscreenOrientation: String! = "all"
|
||||
private var _fullscreenOrientation: String = "all"
|
||||
private var _fullscreenPlayerPresented = false
|
||||
private var _fullscreenUncontrolPlayerPresented = false // to call events switching full screen mode from player controls
|
||||
private var _filterName: String!
|
||||
@ -741,14 +741,14 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
|
||||
@objc
|
||||
func setIgnoreSilentSwitch(_ ignoreSilentSwitch: String?) {
|
||||
_ignoreSilentSwitch = ignoreSilentSwitch
|
||||
_ignoreSilentSwitch = ignoreSilentSwitch ?? "inherit"
|
||||
RCTPlayerOperations.configureAudio(ignoreSilentSwitch: _ignoreSilentSwitch, mixWithOthers: _mixWithOthers, audioOutput: _audioOutput)
|
||||
applyModifiers()
|
||||
}
|
||||
|
||||
@objc
|
||||
func setMixWithOthers(_ mixWithOthers: String?) {
|
||||
_mixWithOthers = mixWithOthers
|
||||
_mixWithOthers = mixWithOthers ?? "inherit"
|
||||
applyModifiers()
|
||||
}
|
||||
|
||||
@ -1050,9 +1050,9 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
|
||||
@objc
|
||||
func setFullscreenOrientation(_ orientation: String?) {
|
||||
_fullscreenOrientation = orientation
|
||||
_fullscreenOrientation = orientation ?? "all"
|
||||
if _fullscreenPlayerPresented {
|
||||
_playerViewController?.preferredOrientation = orientation
|
||||
_playerViewController?.preferredOrientation = _fullscreenOrientation
|
||||
}
|
||||
}
|
||||
|
||||
@ -1224,7 +1224,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
}
|
||||
|
||||
@objc
|
||||
func setAdTagUrl(_ adTagUrl: String!) {
|
||||
func setAdTagUrl(_ adTagUrl: String?) {
|
||||
_adTagUrl = adTagUrl
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user