I put the m3u8 in GCDWebServer to play. When I use Wi-Fi, it is no problem. But using 4G, appears this problem.
Asked
Active
Viewed 119 times
-5
-
Unwrap optionals safely by using `if let ` – Balaji Galave May 09 '17 at 10:17
2 Answers
0
You are force unwrapping m3u8
in your code. If that's ever nil
, you're going to have a problem. You're saying that it will never be nil when you force unwrap using that !
.
You can use the if let
approach, or you can test for nil
too.
// Are you sure dataServer isn't nil too here?
if let serverAddress = dataServer!.serverURL.URLByAppendingPathComponent(self.m3u8) {
//Should be safe
}
Or
if m3u8 == nil {
print("m3u8 is nil")
return
}

Radagast the Brown
- 387
- 4
- 14
0
I have already solved the problem.When I use 4 g, access to the dataServer!ServerURL is nil.My solution is to give it a local IP
if davServer?.serverURL == nil {
serverAddress = NSURL.init(string: "http://localhost/playts.m3u8")!
}else{
serverAddress = (davServer?.serverURL.URLByAppendingPathComponent(self.m3u8!))!
}

user6354045
- 1
- 2